login.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view class="wrap">
  3. <view class="login">
  4. <view class="login-title">
  5. <h3>手机号登录/注册</h3>
  6. <p>欢迎来到{{projectName}}</p>
  7. <p v-if="activityInfo"><span style="color: red;">*</span>正在参加活动<span style="color: #3fbd70;" ><{{activityInfo.name}}></span></p>
  8. </view>
  9. <view class="login-form">
  10. <view class="login-form-item">
  11. <view class="title">手机号</view>
  12. <view class="input">
  13. <u-input :customStyle="customStyle" :placeholderStyle="placeholderStyle" v-model="form.telephone" type="number" placeholder="请输入手机号" placeholder-style="font-size:16px;color:#ccc;"/>
  14. </view>
  15. <view class="tips">未注册的手机号验证后将自动注册</view>
  16. </view>
  17. <view class="login-form-item">
  18. <view class="title">验证码</view>
  19. <view class="input">
  20. <u-input :customStyle="customStyle" :placeholderStyle="placeholderStyle" v-model="form.verifyCode" type="number" placeholder="请输入验证码" placeholder-style="font-size:16px;color:#ccc;"/>
  21. <view class="code" @click="getCode">{{codeTips}}</view>
  22. </view>
  23. <view style="width: 350px;">
  24. <u-checkbox-group>
  25. <u-checkbox class="tips" active-color="green" v-model="value" shape="circle" @change="checkboxChange()"></u-checkbox>
  26. </u-checkbox-group>
  27. <span>我已阅读并同意</span>
  28. <span @click="gotoUrl('pages/article/details?code=YHXY')" style="color: #3fbd70;">《会员协议》</span>和
  29. <span @click="gotoUrl('pages/article/details?code=YSZC')" style="color: #3fbd70;">《隐私协议》</span>
  30. </view>
  31. </view>
  32. </view>
  33. <u-button :style="[inputStyle]" class="login-btn" type="success" shape="circle" @click="login">登录</u-button>
  34. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start" change-text="已发送(Xs)">
  35. </u-verification-code>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import * as loginApi from '@/apis/login.js'
  41. import * as API from '@/apis/index.js'
  42. import {
  43. checkPhone
  44. } from '@/utils'
  45. export default {
  46. data() {
  47. return {
  48. elderMode:false,
  49. customStyle:{
  50. 'font-size':'28rpx'
  51. },
  52. placeholderStyle:"font-size:28rpx",
  53. form: {
  54. telephone: '',
  55. verifyCode: '',
  56. },
  57. activityInfo:null,
  58. isSendMsgIng: false,
  59. sendMsgSecond: 60,
  60. codeTips: '',
  61. value: false,
  62. code: '',
  63. codeId: '',
  64. projectName:'',
  65. }
  66. },
  67. computed: {
  68. inputStyle() {
  69. let style = {};
  70. if(this.form.telephone) {
  71. style.color = "#fff";
  72. style.backgroundColor = this.$u.color['success'];
  73. }
  74. return style;
  75. }
  76. },
  77. onLoad(op) {
  78. this.projectName=process.car.ProjectName;
  79. if(op.jpcode) {
  80. var str1 = op.jpcode.slice(0,19);
  81. var str2 = op.jpcode.slice(20,21);
  82. var str3 = op.jpcode.slice(22);
  83. if(str1 == 'jp_team51_charge_id') {
  84. if(str2 == 'A') {
  85. this.code = str2;
  86. this.codeId = str3;
  87. uni.showToast({
  88. title:"注册后享受充电服务"
  89. })
  90. }
  91. }
  92. }
  93. var obj=this.carhelp.get("friends_invitation")
  94. if(obj){
  95. if(obj.date+1000*60*60*24 > new Date().getTime() ){
  96. this.form.inviteId=obj.op.uid
  97. this.form.code=obj.op.icode
  98. this.activityInfo=obj.activityInfo;
  99. }
  100. }
  101. },
  102. onReady() {
  103. this.elderMode = this.carhelp.get('getElderModeClass') == '长辈模式';
  104. if(this.elderMode)
  105. this.theme('elder')
  106. else
  107. this.theme('standard')
  108. },
  109. methods: {
  110. theme(type) {
  111. if(type == 'elder')
  112. {
  113. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  114. let data = {
  115. "font-size":'32rpx',
  116. };
  117. this.customStyle = data;
  118. this.placeholderStyle = "font-size:32rpx";//data;
  119. }
  120. else
  121. {
  122. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  123. let data ={
  124. "font-size":'28rpx',
  125. };
  126. this.customStyle = data;
  127. this.placeholderStyle = "font-size:28rpx";//data;
  128. }
  129. },
  130. codeChange(text) {
  131. this.codeTips = text;
  132. },
  133. start() {
  134. if (!this.isSendMsgIng) {
  135. uni.showLoading({
  136. title: "加载中",
  137. mask: true,
  138. })
  139. loginApi.getVerifyCode(this.form.telephone).then((response) => {
  140. uni.hideLoading();
  141. this.carhelp.set("getvcodetime", new Date().getTime());
  142. if (!"") {
  143. //倒计时
  144. uni.showToast({
  145. title: "发送成功"
  146. })
  147. } else {
  148. uni.showToast({
  149. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  150. })
  151. }
  152. }).catch(error => {
  153. uni.showToast({
  154. title: error,
  155. icon: "none"
  156. })
  157. })
  158. }
  159. },
  160. //倒计时
  161. end() {
  162. this.sendMsgSecond = 60;
  163. this.isSendMsgIng = false;
  164. },
  165. // 获取验证码
  166. getCode() {
  167. if (this.$refs.uCode.canGetCode) {} else {
  168. uni.showToast({
  169. title: '倒计时结束后再发送',
  170. icon: "none"
  171. })
  172. return
  173. }
  174. var checkPhoneResult = checkPhone(this.form.telephone);
  175. if (checkPhoneResult !== true) {
  176. uni.showToast({
  177. title: checkPhoneResult,
  178. })
  179. return;
  180. }
  181. this.$refs.uCode.start();
  182. },
  183. checkboxChange() {
  184. this.value = !this.value;
  185. },
  186. login() {
  187. var checkPhoneResult = checkPhone(this.form.telephone);
  188. if(!this.form.telephone || checkPhoneResult != true) {
  189. uni.showToast({
  190. title: checkPhoneResult,
  191. icon: "none"
  192. })
  193. return;
  194. }
  195. if(!this.form.verifyCode) {
  196. uni.showToast({
  197. title: "请输入验证码",
  198. icon: "none"
  199. })
  200. return
  201. }
  202. if(!this.value) {
  203. uni.showToast({
  204. title: "请勾选协议",
  205. icon: "none"
  206. })
  207. return
  208. }
  209. uni.showLoading({
  210. title: "加载中",
  211. mask: true,
  212. })
  213. this.form.nickName= this.carhelp.getUserInfo().nickname;
  214. this.form.headImg=this.carhelp.getUserInfo().headimgurl;
  215. this.form.openId= this.carhelp.getOpenId();
  216. loginApi.validateCode(this.form).then((response) => {
  217. uni.hideLoading();
  218. var token = response ? response.data.token : '';
  219. this.carhelp.setToken(token);
  220. this.carhelp.setPersonInfo(response.data.regUser);
  221. this.carhelp.set("getElderModeClass", false);
  222. if(!response.data.regUser.carId){
  223. var url="/pages/login/completeInfo?login=1"
  224. if(this.code == 'A') {
  225. url+="&jpcode=jp_team51_charge_id:A_" + this.codeId
  226. }
  227. uni.redirectTo({
  228. url:url
  229. })
  230. }else if(this.code == 'A') {
  231. var k=API.codeOperation("jp_team51_charge_id:A_"+this.codeId);
  232. if(k){
  233. uni.redirectTo({
  234. url:k
  235. })
  236. }
  237. } else {
  238. uni.redirectTo({
  239. url: '/pages/index/index'
  240. })
  241. }
  242. }).catch(error => {
  243. uni.showToast({
  244. title: error,
  245. icon: "none"
  246. })
  247. })
  248. }
  249. }
  250. }
  251. </script>
  252. <style>
  253. page{
  254. background-color: #fff;
  255. }
  256. </style>
  257. <style lang="scss" scoped>
  258. @import "@/_theme.scss";
  259. .all{
  260. @include themeify{
  261. font-size: themed('font-size2');
  262. }
  263. }
  264. /deep/.placeholderStyle {
  265. font-size: themed('font-size2');
  266. }
  267. .wrap {
  268. @include themeify{
  269. font-size: themed('font-size2');
  270. }
  271. /* font-size: 28rpx;*/
  272. .login {
  273. width: 600rpx;
  274. padding-top: 80rpx;
  275. margin: 0 auto;
  276. .login-title {
  277. text-align: left;
  278. h3{
  279. @include themeify{
  280. font-size: themed('font-size7');
  281. }
  282. /* font-size: 48rpx;*/
  283. font-weight: normal;
  284. }
  285. p{
  286. margin-top: 4px;
  287. color:#777
  288. }
  289. }
  290. .login-form-item{
  291. margin-top: 40px;
  292. .title{
  293. margin-bottom: 8px;
  294. @include themeify{
  295. font-size: themed('font-size2');
  296. font-weight: themed('fontWeight');
  297. letter-spacing: themed('letterSpacing');
  298. }
  299. }
  300. .input {
  301. border-bottom: 1px solid #f7f7f7;
  302. position: relative;
  303. }
  304. .code{
  305. position: absolute;
  306. right: 0;
  307. top:7px;
  308. color:#1677FF;
  309. }
  310. .tips {
  311. color: $u-type-info;
  312. margin-top: 12px;
  313. @include themeify{
  314. font-size: themed('font-size1');
  315. }
  316. /* font-size: 12px;*/
  317. span{
  318. color:#3fbd70;
  319. }
  320. }
  321. }
  322. .login-btn {
  323. margin-top: 40px;
  324. background-color: #a7dbc2;
  325. @include themeify{
  326. font-size: themed('font-size3');
  327. }
  328. }
  329. .alternative {
  330. color: $u-tips-color;
  331. display: flex;
  332. justify-content: space-between;
  333. margin-top: 30rpx;
  334. }
  335. }
  336. }
  337. </style>