login.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. <template>
  2. <view class="page">
  3. <view class="header">
  4. <!-- <view class="left"> -->
  5. <!-- <image class="img" mode="widthFix" src="../../static/login/close.png"></image> -->
  6. <!-- </view> -->
  7. <view class="title">登录/注册</view>
  8. <view class="subtitle">手机号登录/注册</view>
  9. </view>
  10. <view class="tbody">
  11. <!-- <view class="tbody" style="position: fixed;top: 70%;left: 50%;transform: translate(-50%,-50%);"> -->
  12. <block v-if="type == 'onelogin'">
  13. <image class="icon" mode="widthFix" src="../../static/me/avator.png"></image>
  14. <text class="mobile">+ 86 1**********</text>
  15. <text class="tips">首次验证通过即注册萌创星球账号</text>
  16. <text class="btn_submit blick-btn-animation">本机号码一键登录</text>
  17. <view class="other">
  18. <view class="pass" @click="type = 'pass'">密码登录</view>
  19. <view class="line"></view>
  20. <view class="mob" @click="type = 'mobile'">手机号登录</view>
  21. </view>
  22. </block>
  23. <block v-if="type == 'pass' || type == 'mobile'">
  24. <template v-if="isSmsLogin">
  25. <view class="name">手机号码:</view>
  26. <view class="item">
  27. <input type="number" class="input" v-model="mobile" placeholder="请输入手机号码" maxlength="11" />
  28. </view>
  29. <block v-if="type == 'pass'">
  30. <view class="name">登录密码:</view>
  31. <view class="item">
  32. <input type="password" class="input" v-model="password" placeholder="请输入登录密码"
  33. maxlength="32" />
  34. </view>
  35. <view class="other_list">
  36. <text class="left" v-if="true" @click="type = 'mobile'">验证码登录</text>
  37. <text class="left" v-else></text>
  38. <text class="right" @click="type = 'mobile'" v-if="false">验证码登录</text>
  39. <text class="right" @click="toRegist">还没有账号?开始注册</text>
  40. </view>
  41. </block>
  42. <block v-if="type == 'mobile'">
  43. <view class="name">验证码:</view>
  44. <view class="item">
  45. <input type="number" class="input" v-model="code" placeholder="请输入验证码" maxlength="6" />
  46. <view class="btn blick-btn-animation" v-if="captchaTime === 0" @click="getCode">获取验证码</view>
  47. <!-- 使用云函数发送验证码 -->
  48. <!-- <view class="btn blick-btn-animation" v-if="captchaTime === 0" @click="sendSms()">获取验证码</view> -->
  49. <view class="btn" v-if="captchaTime > 0">{{ captchaTime }}秒后重试</view>
  50. </view>
  51. <view class="other_list" v-if="false">
  52. <text class="left"></text>
  53. <text class="right" @click="type = 'pass'" style="color: blue;">密码登录</text>
  54. </view>
  55. </block>
  56. <text class="btn_submit white" @click="toLogin">登录/注册</text>
  57. <text class="btn_submit blick-btn-animation" @click="oneClickLoginFun">一键登录</text>
  58. </template>
  59. <template v-else>
  60. <view
  61. style="width: 100%;height: 500rpx;display: flex;justify-content: center;align-items: flex-end;">
  62. <text class="btn_submit blick-btn-animation" @click="oneClickLoginFun">一键登录</text>
  63. </view>
  64. </template>
  65. </block>
  66. <view class="wechat" v-if="false">
  67. <image class="img" mode="widthFix" src="../../static/login/wechat.png"></image>
  68. </view>
  69. <view class="agree">
  70. <view class="agree2" @click="agreeChk()">
  71. <image mode="widthFix" src="../../static/icon/wd_icon_gouxuan04.png" v-if="is_agree == 0"></image>
  72. <image mode="widthFix" src="../../static/icon/wd_icon_gouxuan05.png" v-if="is_agree == 1"></image>
  73. <text>我已阅读并同意</text>
  74. </view>
  75. <text class="xy" @click="goWeb('https://e.zhichao.art/web/yszc.php', '隐私协议')">
  76. 隐私协议
  77. </text>
  78. 》和《
  79. <text class="xy" @click="goWeb('https://e.zhichao.art/web/yhxy.php', '用户使用协议')">
  80. 用户使用协议
  81. </text>
  82. </view>
  83. <view class="agree" v-if="false"><text class="agree2">{{ push_token }}</text></view>
  84. </view>
  85. <view class="blankHeight"></view>
  86. <DialogBox ref="DialogBox"></DialogBox>
  87. </view>
  88. </template>
  89. <script>
  90. import pubc from '@/common/public.js'
  91. import { mapState } from 'vuex'
  92. import channel from "@/common/channel.js";
  93. import verificationCode from '@/common/verificationCode';
  94. export default {
  95. components: {},
  96. computed: {
  97. ...mapState('hideModule', ['isSmsLogin'])
  98. },
  99. data() {
  100. return {
  101. skey: '',
  102. sel: 1,
  103. is_agree: 0,
  104. type: 'mobile',
  105. redirectUrl: '',
  106. callback: null,
  107. myinfo: {
  108. nickname: '',
  109. join_name: '',
  110. num_1: 0,
  111. num_2: 0,
  112. num_3: 0,
  113. num_4: 0,
  114. is_login: 'no',
  115. num_history: 0,
  116. num_collection: 0
  117. },
  118. mobile: '',
  119. password: '',
  120. code: '',
  121. captchaTime: 0,
  122. push_token: '',
  123. lat: '',
  124. lng: '',
  125. univerifyStyle: {
  126. "fullScreen": false, // 是否全屏显示,默认值: false
  127. "backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff
  128. "backgroundImage": "", // 全屏显示的背景图片,默认值:"" (仅支持本地图片,只有全屏显示时支持)
  129. "icon": {
  130. "path": "/static/logo.png", // 自定义显示在授权框中的logo,仅支持本地图片 默认显示App logo
  131. "width": "60px", //图标宽度 默认值:60px
  132. "height": "60px" //图标高度 默认值:60px
  133. },
  134. "closeIcon": {
  135. // "path": "/static/icon/whiteBackground.png", // 自定义显示在授权框中的取消图片,仅支持本地图片
  136. "width": "60px", //图标宽度 默认值:60px (HBuilderX 4.0+ 仅iOS支持)
  137. "height": "60px" //图标高度 默认值:60px (HBuilderX 4.0+ 仅iOS支持)
  138. },
  139. "phoneNum": {
  140. "color": "#202020" // 手机号文字颜色 默认值:#202020
  141. },
  142. "slogan": {
  143. "color": "#BBBBBB" // slogan 字体颜色 默认值:#BBBBBB
  144. },
  145. "authButton": {
  146. "normalColor": "#131313", // 授权按钮正常状态背景颜色 默认值:#3479f5
  147. "highlightColor": "#131313", // 授权按钮按下状态背景颜色 默认值:#2861c5(仅ios支持)
  148. "disabledColor": "#73aaf5", // 授权按钮不可点击时背景颜色 默认值:#73aaf5(仅ios支持)
  149. "textColor": "#ffffff", // 授权按钮文字颜色 默认值:#ffffff
  150. "title": "本机号码一键登录", // 授权按钮文案 默认值:"本机号码一键登录"
  151. "borderRadius": "24px" // 授权按钮圆角 默认值:"24px" (按钮高度的一半)
  152. },
  153. "otherLoginButton": {
  154. "visible": false, // 是否显示其他登录按钮,默认值:true
  155. "normalColor": "", // 其他登录按钮正常状态背景颜色 默认值:透明
  156. "highlightColor": "", // 其他登录按钮按下状态背景颜色 默认值:透明
  157. "textColor": "#656565", // 其他登录按钮文字颜色 默认值:#656565
  158. "title": "其他登录方式", // 其他登录方式按钮文字 默认值:"其他登录方式"
  159. "borderColor": "", //边框颜色 默认值:透明(仅iOS支持)
  160. "borderRadius": "0px" // 其他登录按钮圆角 默认值:"24px" (按钮高度的一半)
  161. },
  162. "privacyTerms": {
  163. "defaultCheckBoxState": false, // 条款勾选框初始状态 默认值: true
  164. "isCenterHint": true, //未勾选服务条款时点击登录按钮的提示是否居中显示 默认值: false (3.7.13+ 版本支持)
  165. "uncheckedImage": "/static/icon/wd_icon_gouxuan04.png", // 可选 条款勾选框未选中状态图片(仅支持本地图片 建议尺寸 24x24px)(3.2.0+ 版本支持)
  166. "checkedImage": "/static/icon/wd_icon_gouxuan05.png", // 可选 条款勾选框选中状态图片(仅支持本地图片 建议尺寸24x24px)(3.2.0+ 版本支持)
  167. "checkBoxSize": 20, // 可选 条款勾选框大小
  168. "textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB
  169. "termsColor": "#5496E3", // 协议文字颜色 默认值: #5496E3
  170. "prefix": "我已阅读并同意", // 条款前的文案 默认值:"我已阅读并同意"
  171. "suffix": "并使用本机号码登录", // 条款后的文案 默认值:"并使用本机号码登录"
  172. "privacyItems": [ // 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
  173. {
  174. "url": "https://e.zhichao.art/web/yszc.php", // 点击跳转的协议详情页面
  175. "title": "隐私协议" // 协议名称
  176. },
  177. {
  178. "url": "https://e.zhichao.art/web/yhxy.php", // 点击跳转的协议详情页面
  179. "title": "用户使用协议" // 协议名称
  180. }
  181. ]
  182. },
  183. "buttons": { // 自定义页面下方按钮仅全屏模式生效(3.1.14+ 版本支持)
  184. "iconWidth": "45px", // 图标宽度(高度等比例缩放) 默认值:45px
  185. "list": [
  186. {
  187. "provider": "apple",
  188. // "iconPath": "/static/apple.png" // 图标路径仅支持本地图片
  189. },
  190. {
  191. "provider": "weixin",
  192. // "iconPath": "/static/wechat.png" // 图标路径仅支持本地图片
  193. }
  194. ]
  195. }
  196. },
  197. templateId :36155,//短信模板ID
  198. expMinute:'15', //短信有效时间
  199. randomVerificationCode:'',
  200. }
  201. },
  202. onLoad() {
  203. // 获取页面传递的数据
  204. const eventChannel = this.getOpenerEventChannel();
  205. eventChannel.on('acceptDataFromOpener', (data) => {
  206. this.redirectUrl = data.redirectUrl;
  207. });
  208. setTimeout(function () {
  209. console.log(this.isSmsLogin, 'isSmsLogin');
  210. uni.setNavigationBarColor({
  211. frontColor: '#ffffff',
  212. backgroundColor: '#00000000',
  213. animation: {
  214. duration: 400,
  215. timingFunc: 'easeIn'
  216. }
  217. })
  218. }, 200);
  219. let that = this;
  220. uni.getPushClientId({
  221. success: (res) => {
  222. console.log("su:", res.cid);
  223. that.push_token = res.cid;
  224. },
  225. fail(err) {
  226. that.push_token = '';
  227. console.log(err)
  228. }
  229. });
  230. let channelStr = channel && channel.getCurrentStore() && channel.getCurrentStore().channel;
  231. if (channelStr && channelStr == 'huawei') {
  232. this.univerifyStyle.privacyTerms.defaultCheckBoxState = false;
  233. } else {
  234. this.univerifyStyle.privacyTerms.defaultCheckBoxState = true;
  235. }
  236. this.oneClickLoginFun(channel);
  237. },
  238. onShow() {
  239. // let hsign = pubc.Encrypt("aboa-wifl-kwfl-zjfk-wlaa_FA0412932BAE9D98506580ADB348BEF9");
  240. // console.log("hsign", hsign)
  241. // let skey = uni.getStorageSync("wapptoken");
  242. // if (skey != null && skey != "" && skey != undefined) {
  243. // uni.switchTab({
  244. // url: "/pages/index/index"
  245. // });
  246. // return;
  247. // }
  248. // let that = this;
  249. // uni.getLocation({
  250. // type: 'wgs84',
  251. // success: function(res) {
  252. // that.lat = res.latitude;
  253. // that.lng = res.longitude;
  254. // },
  255. // fail: function(error) {
  256. // console.error('获取位置失败:', error);
  257. // }
  258. // });
  259. },
  260. methods: {
  261. goWeb(url, title) {
  262. uni.navigateTo({
  263. url: `/pages/webview/index?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}`
  264. })
  265. },
  266. onBack() { },
  267. agreeChk() {
  268. if (this.is_agree == 0) {
  269. this.is_agree = 1;
  270. } else {
  271. this.is_agree = 0;
  272. }
  273. },
  274. goPage(page) {
  275. if (page == 'yhxy') {
  276. uni.navigateTo({
  277. url: '/pages/AboutUs/yhxy'
  278. })
  279. } else if (page == 'yszc') {
  280. // #ifdef APP-PLUS
  281. plus.runtime.openWeb('https://e.zhichao.art/web/yszc.php') // plus.runtime.openWeb(href);
  282. // #endif
  283. // #ifdef H5
  284. window.open('https://e.zhichao.art/web/yszc.php')
  285. // #endif
  286. // uni.navigateTo({
  287. // url: '/pages/AboutUs/yszc'
  288. // })
  289. } else {
  290. uni.navigateTo({
  291. url: page,
  292. });
  293. }
  294. },
  295. toRegist() {
  296. uni.navigateTo({
  297. url: "/pages/login/reg",
  298. });
  299. },
  300. toLogin() {
  301. let that = this;
  302. if (this.mobile.length != 11) {
  303. uni.showToast({
  304. title: "请输入手机号",
  305. icon: "none",
  306. });
  307. return;
  308. }
  309. if (this.type == 'pass') {
  310. if (this.password.length < 6) {
  311. uni.showToast({
  312. title: "请输入不小于6位的密码",
  313. icon: "none",
  314. });
  315. return;
  316. }
  317. } else {
  318. if (this.code.length < 4) {
  319. uni.showToast({
  320. title: "请输入手机验证码",
  321. icon: "none",
  322. });
  323. return;
  324. }
  325. }
  326. if (this.is_agree == 0) {
  327. uni.showToast({
  328. title: "请确认并选择协议",
  329. icon: "none",
  330. });
  331. return;
  332. }
  333. let method = '/Member/gamelogin';
  334. if (this.btn_type == 'reg') {
  335. method = '/Member/register';
  336. if (this.code.length < 4) {
  337. uni.showToast({
  338. title: '请输入验证码',
  339. icon: 'none'
  340. });
  341. return;
  342. }
  343. } else if (this.btn_type == 'reset') {
  344. method = '/Member/resetPass';
  345. if (this.code.length < 4) {
  346. uni.showToast({
  347. title: '请输入验证码',
  348. icon: 'none'
  349. });
  350. return;
  351. }
  352. }
  353. this.loginInterface({ isOneClickLogin: false, phone: '' },)
  354. },
  355. loginInterface({ isOneClickLogin, phone }) {
  356. let that = this;
  357. let channel = "";
  358. // #ifdef APP-PLUS
  359. channel = plus.runtime.channel;
  360. // #endif
  361. uni.showLoading({
  362. mask: true,
  363. });
  364. console.log("host", this.$apiHost + method);
  365. let mobile = this.mobile;
  366. let code = this.code;
  367. let type = this.type;
  368. console.log(type, 89);
  369. let method = '/Member/gamelogin';
  370. if (isOneClickLogin) {
  371. mobile = phone;
  372. code = '123601';
  373. type = 'mobile';
  374. }
  375. uni.request({
  376. url: this.$apiHost + method,
  377. data: {
  378. uuid: getApp().globalData.uuid,
  379. channel: channel,
  380. loginType: type,
  381. mobile,
  382. password: this.password,
  383. code,
  384. push_token: this.push_token,
  385. lat: this.lat,
  386. lng: this.lng,
  387. },
  388. header: {
  389. "content-type": "application/json",
  390. },
  391. success: (res) => {
  392. console.log("----", res.data);
  393. if (res.data.success == "yes") {
  394. uni.showToast({
  395. title: "登录成功",
  396. icon: "none",
  397. });
  398. console.log("res.data", res.data);
  399. if (res.data.uuid.length > 5) {
  400. uni.setStorageSync("app_uuid", res.data.uuid);
  401. getApp().globalData.uuid = res.data.uuid;
  402. }
  403. uni.setStorageSync("is_login", "yes");
  404. uni.setStorageSync("wapptoken", res.data.skey);
  405. getApp().globalData.skey = res.data.skey;
  406. if (res.data.header_c != "") {
  407. getApp().globalData.headerSign = pubc.Encrypt(res.data.header_c + "_" +
  408. getApp().globalData.uuid);
  409. uni.setStorageSync("headerSign", getApp().globalData.headerSign);
  410. }
  411. getApp().globalData.headerC = res.data.header_c;
  412. if (res.data.nickname == '') {
  413. uni.redirectTo({
  414. url: '/pages/my/step'
  415. });
  416. return;
  417. }
  418. // 获取用户信息储存全局
  419. uni.request({
  420. url: this.$apiHost + '/User/getinfo',
  421. data: {
  422. uuid: getApp().globalData.uuid,
  423. skey: getApp().globalData.skey
  424. },
  425. header: {
  426. "content-type": "application/json",
  427. 'sign': getApp().globalData.headerSign
  428. },
  429. success: (res) => {
  430. console.log("--获取用户信息--:", res.data);
  431. if (res.data.need_login == "yes") {
  432. }
  433. if (res.data.aihao) {
  434. this.aihao_tags = res.data.aihao.split(",");
  435. }
  436. if (res.data.nickname) {
  437. getApp().globalData.nickname = res.data.nickname
  438. uni.removeStorageSync("nickname");
  439. uni.setStorageSync("nickname", res.data.nickname);
  440. }
  441. if (res.data.mobile) {
  442. getApp().globalData.mobile = res.data.mobile
  443. uni.removeStorageSync("mobile", res.data.mobile);
  444. uni.setStorageSync("mobile", res.data.mobile);
  445. }
  446. if (res.data.user_id) {
  447. getApp().globalData.user_id = res.data.user_id
  448. uni.removeStorageSync("user_id");
  449. uni.setStorageSync("user_id", res.data.user_id);
  450. }
  451. if (res.data.avator) {
  452. getApp().globalData.avator = res.data.avator
  453. uni.removeStorageSync("avator");
  454. uni.setStorageSync("avator", res.data.avator);
  455. }
  456. // 执行回调函数
  457. if (this.redirectUrl) {
  458. console.log("跳转到页面", this.redirectUrl);
  459. var tabArray = ["pages/index/index", "pages/make/index", "pages/message/mailMessage", "pages/my/my"];
  460. // 获取基础路由路径(不包含参数)
  461. var baseUrl = this.redirectUrl.split('?')[0];
  462. // 判断是否是tabbar页面
  463. if (tabArray.includes(baseUrl)) {
  464. uni.switchTab({
  465. url: '/' + baseUrl
  466. });
  467. } else {
  468. uni.redirectTo({
  469. url: '/' + this.redirectUrl
  470. });
  471. }
  472. return;
  473. }
  474. uni.switchTab({
  475. url: "/pages/index/index",
  476. });
  477. },
  478. complete: (com) => {
  479. // uni.hideLoading();
  480. },
  481. fail: (e) => {
  482. console.log("----e:", e);
  483. }
  484. });
  485. } else if (res.data.success == "no") {
  486. uni.showToast({
  487. title: res.data.str,
  488. icon: "none",
  489. });
  490. } else {
  491. uni.showToast({
  492. title: "操作失败,请联系客服",
  493. icon: "none",
  494. });
  495. }
  496. },
  497. complete: (com) => {
  498. uni.hideLoading();
  499. },
  500. });
  501. },
  502. getCode() {
  503. if (this.mobile.length != 11) {
  504. uni.showToast({
  505. title: '请输入手机号',
  506. icon: 'none'
  507. });
  508. return;
  509. }
  510. if (this.captchaTime > 0) {
  511. uni.showToast({
  512. title: '不能重复获取',
  513. icon: 'none'
  514. });
  515. return;
  516. }
  517. this.captchaTime = 60;
  518. uni.request({
  519. url: this.$apiHost + '/Web/getcode', //仅为示例,并非真实接口地址。
  520. data: {
  521. skey: this.skey,
  522. mobile: this.mobile,
  523. },
  524. header: {
  525. 'content-type': 'application/json' //自定义请求头信息
  526. },
  527. success: (res) => {
  528. console.log("----", res.data)
  529. uni.showToast({
  530. title: res.data.str,
  531. icon: 'none'
  532. })
  533. if (res.data.success == 'yes') {
  534. this.getCodeTime();
  535. } else {
  536. this.captchaTime = 0;
  537. }
  538. }
  539. });
  540. },
  541. getCodeTime() {
  542. if (this.captchaTime > 0) {
  543. setTimeout(() => {
  544. this.captchaTime--;
  545. this.getCodeTime();
  546. }, 1000);
  547. }
  548. },
  549. oneClickLoginFun() {
  550. let _this = this;
  551. //预登陆
  552. uni.preLogin({
  553. provider: 'univerify',
  554. success() { //预登录成功
  555. // 显示一键登录选项
  556. uni.login({
  557. provider: 'univerify',
  558. univerifyStyle: _this.univerifyStyle,
  559. success(res) { // 登录成功
  560. console.log(res.authResult.access_token);
  561. console.log(res.authResult.openid);
  562. // 此处获取了openid和access_token
  563. // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
  564. // 通过uniCloud.callFunction函数实现前端获取手机号
  565. uniCloud.callFunction({
  566. name: "oneClickLogin", // 填写你自己的云函数名称
  567. //传入上面获取的openid和access_token获取手机号
  568. data: {
  569. access_token: res.authResult.access_token, // 客户端一键登录接口返回的access_token
  570. openid: res.authResult.openid // 客户端一键登录接口返回的openid
  571. }
  572. }).then((dataRes) => {
  573. //此处已经成功获取手机号等信息
  574. console.log("云函数返回的参数1", dataRes)
  575. let phone = dataRes.result.data.phoneNumber
  576. if (phone) {
  577. _this.loginInterface({
  578. isOneClickLogin: true,
  579. phone,
  580. })
  581. setTimeout(() => {
  582. uni.closeAuthView() //关闭一键登录弹出窗口
  583. }, 500)
  584. } else {
  585. }
  586. // 获取手机号后根据自己的需求做后面的登录操作即可
  587. //...
  588. }).catch((err) => {
  589. console.log(err);
  590. console.log("云函数报错", err)
  591. uni.showToast({
  592. title: err.errMsg,
  593. icon: "none"
  594. })
  595. this_ = this
  596. setTimeout(() => {
  597. uni.closeAuthView() //关闭一键登录弹出窗口
  598. _this.onClickMsgLogin()
  599. uni.showToast({
  600. title: "请插入SIM卡并且使用流量后再重试",
  601. icon: "none"
  602. })
  603. }, 500)
  604. })
  605. },
  606. fail(res) { // 登录失败
  607. console.log(res.errCode)
  608. console.log(res.errMsg)
  609. }
  610. })
  611. },
  612. fail(res) {
  613. // 预登录失败
  614. // 不显示一键登录选项(或置灰)
  615. // 根据错误信息判断失败原因,如有需要可将错误提交给统计服务器
  616. console.log(res.errCode)
  617. console.log(res.errMsg)
  618. _this.onClickMsgLogin()
  619. uni.hideToast();
  620. uni.showToast({
  621. title: "请插入SIM卡并且使用流量后再重试",
  622. icon: "none",
  623. duration: 3000
  624. })
  625. }
  626. })
  627. },
  628. // 一键登录失败
  629. onClickMsgLogin() {
  630. uni.closeAuthView()
  631. uni.hideToast();
  632. setTimeout(() => {
  633. uni.showToast({
  634. title: "请插入SIM卡并且使用流量后再重试",
  635. icon: "none",
  636. duration: 3000
  637. })
  638. }, 500)
  639. },
  640. // 发送短信验证码
  641. sendSms() {
  642. // 手机号格式验证
  643. const mobileRegex = /^1[3-9]\d{9}$/;
  644. if (!this.mobile) {
  645. uni.showToast({
  646. title: '请输入手机号',
  647. icon: 'none'
  648. });
  649. return;
  650. }
  651. if (!mobileRegex.test(this.mobile)) {
  652. uni.showToast({
  653. title: '请输入正确的手机号',
  654. icon: 'none'
  655. });
  656. return;
  657. }
  658. // 检查是否在倒计时中
  659. if (this.captchaTime > 0) {
  660. uni.showToast({
  661. title: '不能重复获取',
  662. icon: 'none'
  663. });
  664. return;
  665. }
  666. // 生成验证码
  667. const code = verificationCode.generateCode();
  668. console.log("生成的验证码:", code);
  669. console.log({templateId: this.templateId,
  670. phone: this.mobile,
  671. code: code,
  672. expMinute: this.expMinute});
  673. // 调用云函数发送验证码
  674. uniCloud.callFunction({
  675. name: "smsVerification",
  676. data: {
  677. templateId: this.templateId + '',
  678. phone: this.mobile + '',
  679. code: code + '',
  680. expMinute: this.expMinute + '',
  681. name: '萌创星球',
  682. }
  683. }).then((dataRes) => {
  684. console.log("云函数返回的参数", dataRes);
  685. if (dataRes.result && dataRes.result.success) {
  686. uni.showToast({
  687. title: '验证码发送成功',
  688. icon: 'none'
  689. });
  690. // 开始倒计时
  691. this.captchaTime = 60;
  692. this.getCodeTime();
  693. } else {
  694. uni.showToast({
  695. title: dataRes.result.message || '验证码发送失败',
  696. icon: 'none'
  697. });
  698. this.captchaTime = 0;
  699. }
  700. }).catch((err) => {
  701. console.log("发送验证码失败:", err);
  702. uni.showToast({
  703. title: '验证码发送失败',
  704. icon: 'none'
  705. });
  706. this.captchaTime = 0;
  707. });
  708. },
  709. }
  710. }
  711. </script>
  712. <style scoped lang="scss">
  713. @import 'login.scss';
  714. </style>