login.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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 {
  92. mapState
  93. } from 'vuex'
  94. import channel from "@/common/channel.js";
  95. import verificationCode from '@/common/verificationCode';
  96. export default {
  97. components: {},
  98. computed: {
  99. ...mapState('hideModule', ['isSmsLogin'])
  100. },
  101. data() {
  102. return {
  103. skey: '',
  104. sel: 1,
  105. is_agree: 0,
  106. type: 'mobile',
  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. "provider": "apple",
  187. // "iconPath": "/static/apple.png" // 图标路径仅支持本地图片
  188. },
  189. {
  190. "provider": "weixin",
  191. // "iconPath": "/static/wechat.png" // 图标路径仅支持本地图片
  192. }
  193. ]
  194. }
  195. },
  196. templateId: 36155, //短信模板ID
  197. expMinute: '15', //短信有效时间
  198. randomVerificationCode: '',
  199. }
  200. },
  201. onLoad() {
  202. setTimeout(function() {
  203. console.log(this.isSmsLogin, 'isSmsLogin');
  204. uni.setNavigationBarColor({
  205. frontColor: '#ffffff',
  206. backgroundColor: '#00000000',
  207. animation: {
  208. duration: 400,
  209. timingFunc: 'easeIn'
  210. }
  211. })
  212. }, 200);
  213. let that = this;
  214. // uni.getPushClientId({
  215. // success: (res) => {
  216. // console.log("su:", res.cid);
  217. // that.push_token = res.cid;
  218. // },
  219. // fail(err) {
  220. // that.push_token = '';
  221. // console.log(err)
  222. // }
  223. // });
  224. let channelStr = channel && channel.getCurrentStore() && channel.getCurrentStore().channel;
  225. if (channelStr && channelStr == 'huawei') {
  226. this.univerifyStyle.privacyTerms.defaultCheckBoxState = false;
  227. } else {
  228. this.univerifyStyle.privacyTerms.defaultCheckBoxState = true;
  229. }
  230. this.oneClickLoginFun(channel);
  231. },
  232. onShow() {
  233. // let hsign = pubc.Encrypt("aboa-wifl-kwfl-zjfk-wlaa_FA0412932BAE9D98506580ADB348BEF9");
  234. // console.log("hsign", hsign)
  235. // let skey = uni.getStorageSync("wapptoken");
  236. // if (skey != null && skey != "" && skey != undefined) {
  237. // uni.switchTab({
  238. // url: "/pages/index/index"
  239. // });
  240. // return;
  241. // }
  242. // let that = this;
  243. // uni.getLocation({
  244. // type: 'wgs84',
  245. // success: function(res) {
  246. // that.lat = res.latitude;
  247. // that.lng = res.longitude;
  248. // },
  249. // fail: function(error) {
  250. // console.error('获取位置失败:', error);
  251. // }
  252. // });
  253. },
  254. methods: {
  255. goWeb(url, title) {
  256. uni.navigateTo({
  257. url: `/pages/webview/index?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}`
  258. })
  259. },
  260. onBack() {},
  261. agreeChk() {
  262. if (this.is_agree == 0) {
  263. this.is_agree = 1;
  264. } else {
  265. this.is_agree = 0;
  266. }
  267. },
  268. goPage(page) {
  269. if (page == 'yhxy') {
  270. uni.navigateTo({
  271. url: '/pages/AboutUs/yhxy'
  272. })
  273. } else if (page == 'yszc') {
  274. // #ifdef APP-PLUS
  275. plus.runtime.openWeb('https://e.zhichao.art/web/yszc.php') // plus.runtime.openWeb(href);
  276. // #endif
  277. // #ifdef H5
  278. window.open('https://e.zhichao.art/web/yszc.php')
  279. // #endif
  280. // uni.navigateTo({
  281. // url: '/pages/AboutUs/yszc'
  282. // })
  283. } else {
  284. uni.navigateTo({
  285. url: page,
  286. });
  287. }
  288. },
  289. toRegist() {
  290. uni.navigateTo({
  291. url: "/pages/login/reg",
  292. });
  293. },
  294. toLogin() {
  295. let that = this;
  296. if (this.mobile.length != 11) {
  297. uni.showToast({
  298. title: "请输入手机号",
  299. icon: "none",
  300. });
  301. return;
  302. }
  303. if (this.type == 'pass') {
  304. if (this.password.length < 6) {
  305. uni.showToast({
  306. title: "请输入不小于6位的密码",
  307. icon: "none",
  308. });
  309. return;
  310. }
  311. } else {
  312. if (this.code.length < 4) {
  313. uni.showToast({
  314. title: "请输入手机验证码",
  315. icon: "none",
  316. });
  317. return;
  318. }
  319. }
  320. if (this.is_agree == 0) {
  321. uni.showToast({
  322. title: "请确认并选择协议",
  323. icon: "none",
  324. });
  325. return;
  326. }
  327. let method = '/Member/gamelogin';
  328. if (this.btn_type == 'reg') {
  329. method = '/Member/register';
  330. if (this.code.length < 4) {
  331. uni.showToast({
  332. title: '请输入验证码',
  333. icon: 'none'
  334. });
  335. return;
  336. }
  337. } else if (this.btn_type == 'reset') {
  338. method = '/Member/resetPass';
  339. if (this.code.length < 4) {
  340. uni.showToast({
  341. title: '请输入验证码',
  342. icon: 'none'
  343. });
  344. return;
  345. }
  346. }
  347. this.loginInterface({
  348. isOneClickLogin: false,
  349. phone: ''
  350. }, )
  351. },
  352. loginInterface({
  353. isOneClickLogin,
  354. phone
  355. }) {
  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. complete: (com) => {
  458. // uni.hideLoading();
  459. },
  460. fail: (e) => {
  461. console.log("----e:", e);
  462. }
  463. });
  464. uni.switchTab({
  465. url: "/pages/index/index",
  466. });
  467. } else if (res.data.success == "no") {
  468. uni.showToast({
  469. title: res.data.str,
  470. icon: "none",
  471. });
  472. } else {
  473. uni.showToast({
  474. title: "操作失败,请联系客服",
  475. icon: "none",
  476. });
  477. }
  478. },
  479. complete: (com) => {
  480. uni.hideLoading();
  481. },
  482. });
  483. },
  484. getCode() {
  485. if (this.mobile.length != 11) {
  486. uni.showToast({
  487. title: '请输入手机号',
  488. icon: 'none'
  489. });
  490. return;
  491. }
  492. if (this.captchaTime > 0) {
  493. uni.showToast({
  494. title: '不能重复获取',
  495. icon: 'none'
  496. });
  497. return;
  498. }
  499. this.captchaTime = 60;
  500. uni.request({
  501. url: this.$apiHost + '/Web/getcode', //仅为示例,并非真实接口地址。
  502. data: {
  503. skey: this.skey,
  504. mobile: this.mobile,
  505. },
  506. header: {
  507. 'content-type': 'application/json' //自定义请求头信息
  508. },
  509. success: (res) => {
  510. console.log("----", res.data)
  511. uni.showToast({
  512. title: res.data.str,
  513. icon: 'none'
  514. })
  515. if (res.data.success == 'yes') {
  516. this.getCodeTime();
  517. } else {
  518. this.captchaTime = 0;
  519. }
  520. }
  521. });
  522. },
  523. getCodeTime() {
  524. if (this.captchaTime > 0) {
  525. setTimeout(() => {
  526. this.captchaTime--;
  527. this.getCodeTime();
  528. }, 1000);
  529. }
  530. },
  531. oneClickLoginFun() {
  532. let _this = this;
  533. //预登陆
  534. uni.preLogin({
  535. provider: 'univerify',
  536. success() { //预登录成功
  537. // 显示一键登录选项
  538. uni.login({
  539. provider: 'univerify',
  540. univerifyStyle: _this.univerifyStyle,
  541. success(res) { // 登录成功
  542. console.log(res.authResult.access_token);
  543. console.log(res.authResult.openid);
  544. // 此处获取了openid和access_token
  545. // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
  546. // 通过uniCloud.callFunction函数实现前端获取手机号
  547. uniCloud.callFunction({
  548. name: "oneClickLogin", // 填写你自己的云函数名称
  549. //传入上面获取的openid和access_token获取手机号
  550. data: {
  551. access_token: res.authResult
  552. .access_token, // 客户端一键登录接口返回的access_token
  553. openid: res.authResult.openid // 客户端一键登录接口返回的openid
  554. }
  555. }).then((dataRes) => {
  556. //此处已经成功获取手机号等信息
  557. console.log("云函数返回的参数1", dataRes)
  558. let phone = dataRes.result.data.phoneNumber
  559. if (phone) {
  560. _this.loginInterface({
  561. isOneClickLogin: true,
  562. phone,
  563. })
  564. setTimeout(() => {
  565. uni.closeAuthView() //关闭一键登录弹出窗口
  566. }, 500)
  567. } else {
  568. }
  569. // 获取手机号后根据自己的需求做后面的登录操作即可
  570. //...
  571. }).catch((err) => {
  572. console.log(err);
  573. console.log("云函数报错", err)
  574. uni.showToast({
  575. title: err.errMsg,
  576. icon: "none"
  577. })
  578. this_ = this
  579. setTimeout(() => {
  580. uni.closeAuthView() //关闭一键登录弹出窗口
  581. _this.onClickMsgLogin()
  582. uni.showToast({
  583. title: "请插入SIM卡并且使用流量后再重试",
  584. icon: "none"
  585. })
  586. }, 500)
  587. })
  588. },
  589. fail(res) { // 登录失败
  590. console.log(res.errCode)
  591. console.log(res.errMsg)
  592. }
  593. })
  594. },
  595. fail(res) {
  596. // 预登录失败
  597. // 不显示一键登录选项(或置灰)
  598. // 根据错误信息判断失败原因,如有需要可将错误提交给统计服务器
  599. console.log(res.errCode)
  600. console.log(res.errMsg)
  601. _this.onClickMsgLogin()
  602. uni.hideToast();
  603. uni.showToast({
  604. title: "请插入SIM卡并且使用流量后再重试",
  605. icon: "none",
  606. duration: 3000
  607. })
  608. }
  609. })
  610. },
  611. // 一键登录失败
  612. onClickMsgLogin() {
  613. uni.closeAuthView()
  614. uni.hideToast();
  615. setTimeout(() => {
  616. uni.showToast({
  617. title: "请插入SIM卡并且使用流量后再重试",
  618. icon: "none",
  619. duration: 3000
  620. })
  621. }, 500)
  622. },
  623. // 发送短信验证码
  624. sendSms() {
  625. // 手机号格式验证
  626. const mobileRegex = /^1[3-9]\d{9}$/;
  627. if (!this.mobile) {
  628. uni.showToast({
  629. title: '请输入手机号',
  630. icon: 'none'
  631. });
  632. return;
  633. }
  634. if (!mobileRegex.test(this.mobile)) {
  635. uni.showToast({
  636. title: '请输入正确的手机号',
  637. icon: 'none'
  638. });
  639. return;
  640. }
  641. // 检查是否在倒计时中
  642. if (this.captchaTime > 0) {
  643. uni.showToast({
  644. title: '不能重复获取',
  645. icon: 'none'
  646. });
  647. return;
  648. }
  649. // 生成验证码
  650. const code = verificationCode.generateCode();
  651. console.log("生成的验证码:", code);
  652. console.log({
  653. templateId: this.templateId,
  654. phone: this.mobile,
  655. code: code,
  656. expMinute: this.expMinute
  657. });
  658. // 调用云函数发送验证码
  659. uniCloud.callFunction({
  660. name: "smsVerification",
  661. data: {
  662. templateId: this.templateId + '',
  663. phone: this.mobile + '',
  664. code: code + '',
  665. expMinute: this.expMinute + '',
  666. name: '萌创星球',
  667. }
  668. }).then((dataRes) => {
  669. console.log("云函数返回的参数", dataRes);
  670. if (dataRes.result && dataRes.result.success) {
  671. uni.showToast({
  672. title: '验证码发送成功',
  673. icon: 'none'
  674. });
  675. // 开始倒计时
  676. this.captchaTime = 60;
  677. this.getCodeTime();
  678. } else {
  679. uni.showToast({
  680. title: dataRes.result.message || '验证码发送失败',
  681. icon: 'none'
  682. });
  683. this.captchaTime = 0;
  684. }
  685. }).catch((err) => {
  686. console.log("发送验证码失败:", err);
  687. uni.showToast({
  688. title: '验证码发送失败',
  689. icon: 'none'
  690. });
  691. this.captchaTime = 0;
  692. });
  693. },
  694. }
  695. }
  696. </script>
  697. <style scoped lang="scss">
  698. @import 'login.scss';
  699. </style>