login.vue 21 KB

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