smsCode.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="tab-page">
  3. <view class="backimage">
  4. <image class="back" src="/static/image/login/back.png" mode=""></image>
  5. <image class="title-img" src="/static/image/login/code.png" mode=""></image>
  6. <text class="title">验证码已发送至:+86 {{this.info.userName || mobile}}</text>
  7. </view>
  8. <view class="info ">
  9. <!-- #ifdef H5 -->
  10. <u--input v-model="info.smsCode" border="bottom" clearable maxlength="6" placeholderStyle="color:#999"
  11. style="padding: 34rpx 0;box-sizing: border-box;" :focus="true">
  12. <template slot="suffix">
  13. <u-code ref="uCode2" @change="codeChange2" keep-running start-text="发送验证码" style="color: #F9E000;"
  14. uniqueKey="smsCode"></u-code>
  15. <view @tap="getCode2" :text="tips2" class="u-page__code-text">{{tips2}}</view>
  16. </template>
  17. </u--input>
  18. <!-- #endif -->
  19. <!-- #ifdef APP-PLUS -->
  20. <u-input v-model="info.smsCode" border="bottom" clearable maxlength="6" placeholderStyle="color:#999"
  21. style="padding: 34rpx 0;box-sizing: border-box;" :focus="true">
  22. <template slot="suffix">
  23. <u-code ref="uCode2" @change="codeChange2" keep-running start-text="发送验证码" style="color: #F9E000;"
  24. uniqueKey="smsCode"></u-code>
  25. <view @tap="getCode2" :text="tips2" class="u-page__code-text">{{tips2}}</view>
  26. </template>
  27. </u-input>
  28. <!-- #endif -->
  29. </view>
  30. <view v-if="routepage == 'pages/set/accountCancellation'" class=" btn dis a-c j-c " @click="confirmLogout">
  31. 确定注销
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import {
  37. mapState,
  38. mapMutations
  39. } from "vuex"
  40. export default {
  41. data() {
  42. return {
  43. isHidePassword: true, //是否隐藏密码
  44. tips2: '',
  45. info: {
  46. userName: "", //账号
  47. system: "APP", //系统code
  48. captcha: "", //验证码
  49. captchaId: "", //验证码id
  50. smsCode: "", //手机验证码
  51. },
  52. routepage: "", // 上一个页面路由
  53. mobile: "",
  54. userId: "",
  55. }
  56. },
  57. onLoad(options) {
  58. let pages = getCurrentPages(); // 当前页面路由
  59. if (pages.length > 1) {
  60. let beforePage = pages[pages.length - 2].route;
  61. this.routepage = beforePage;
  62. }
  63. if (this.routepage == 'pages/login/login') {
  64. let info = JSON.parse(options.info);
  65. this.info.userName = info.userName;
  66. this.info.captcha = info.captcha;
  67. this.info.captchaId = info.captchaId;
  68. } else {
  69. this.mobile = options.mobile;
  70. this.userId = options.userId;
  71. }
  72. },
  73. watch: {
  74. "info.smsCode": {
  75. handler(val) {
  76. if (val.length == 6) {
  77. switch (this.routepage) {
  78. //登录
  79. case 'pages/login/login':
  80. uni.showLoading({
  81. title: '请求登录'
  82. })
  83. setTimeout(() => {
  84. uni.hideLoading();
  85. this.$login({
  86. url: "/auth/login",
  87. data: this.info,
  88. }).then(res => {
  89. if (res) {
  90. return uni.showToast({
  91. title: res.msg,
  92. icon: 'none'
  93. });
  94. }
  95. return;
  96. })
  97. }, 1000);
  98. break;
  99. case 'pages/my/replacePhone':
  100. //更换手机号
  101. this.validateMethod();
  102. break;
  103. default:
  104. }
  105. }
  106. },
  107. deep: true
  108. },
  109. },
  110. onShow() {},
  111. methods: {
  112. ...mapMutations(['emptyUserInfo']),
  113. //注销
  114. async confirmLogout() {
  115. let res = await this.$http.post('/auth/cancel', {
  116. mobile: this.mobile,
  117. smsCode: this.info.smsCode,
  118. });
  119. if (res.code == 200) {
  120. uni.showToast({
  121. title: res.msg,
  122. icon: 'none'
  123. });
  124. this.emptyUserInfo();
  125. setTimeout(() => {
  126. uni.reLaunch({
  127. url: "/pages/login/login"
  128. })
  129. }, 1500);
  130. } else {
  131. uni.showToast({
  132. title: res.msg,
  133. icon: 'none'
  134. });
  135. }
  136. },
  137. //修改密码
  138. confirm() {
  139. //重置密码逻辑
  140. uni.navigateTo({
  141. url: '/pages/login/login'
  142. })
  143. },
  144. codeChange2(text) {
  145. this.tips2 = text;
  146. },
  147. getCode2() {
  148. if (!this.info.userName && !this.mobile) {
  149. uni.showToast({
  150. title: '手机号为空',
  151. icon: 'none'
  152. });
  153. return;
  154. }
  155. if (this.$refs.uCode2.canGetCode) {
  156. this.smsCode();
  157. // 模拟向后端请求验证码
  158. uni.showLoading({
  159. title: '正在获取验证码'
  160. })
  161. setTimeout(() => {
  162. uni.hideLoading();
  163. // 这里此提示会被this.start()方法中的提示覆盖
  164. uni.$u.toast('验证码已发送');
  165. // 通知验证码组件内部开始倒计时
  166. this.$refs.uCode2.start();
  167. }, 1000);
  168. } else {
  169. uni.$u.toast('倒计时结束后再发送');
  170. }
  171. },
  172. async smsCode() {
  173. if (this.routepage == 'pages/login/login') {
  174. let res = await this.$http.get('/auth/sendSmsCode?mobile=' + this.info.userName || this.mobile);
  175. } else {
  176. let res = await this.$http.get('/auth/sendSmsCode?mobile=' + this.mobile);
  177. }
  178. },
  179. //校验
  180. async validateMethod() {
  181. let res = await this.$http.post('/appUser/validateCode', {
  182. mobile: this.mobile,
  183. smsCode: this.info.smsCode,
  184. });
  185. if (res.code == '200' && res.data) {
  186. setTimeout(() => {
  187. uni.navigateTo({
  188. url: '/pages/my/changePhoneNumber?userId=' + this.userId,
  189. })
  190. }, 1000)
  191. } else {
  192. uni.showToast({
  193. title: "验证码错误",
  194. icon: 'none'
  195. });
  196. }
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. page {
  203. background-color: #fff;
  204. }
  205. .backimage {
  206. width: 100%;
  207. height: 503rpx;
  208. background-color: #fff;
  209. position: relative;
  210. .back {
  211. width: 100%;
  212. height: 100%;
  213. }
  214. .title-img {
  215. position: absolute;
  216. top: 247rpx;
  217. left: 60rpx;
  218. width: 387rpx;
  219. height: 91rpx;
  220. }
  221. .title {
  222. position: absolute;
  223. top: 347rpx;
  224. left: 60rpx;
  225. font-size: 36rpx;
  226. color: #1f1f1f;
  227. }
  228. }
  229. .info {
  230. padding: 0 75rpx;
  231. box-sizing: border-box;
  232. .icon-img {
  233. width: 30rpx;
  234. height: 30rpx;
  235. }
  236. }
  237. //登录
  238. .performLogin {
  239. margin-top: 100rpx;
  240. .buttom {
  241. width: 100%;
  242. padding: 19rpx;
  243. box-sizing: border-box;
  244. background-color: #FDE935;
  245. border-radius: 45rpx;
  246. font-weight: bold;
  247. font-size: 36rpx;
  248. color: #1f1f1f;
  249. }
  250. .arigon {
  251. font-size: 28rpx;
  252. color: #666;
  253. padding: 0 30rpx;
  254. box-sizing: border-box;
  255. }
  256. }
  257. .footer {
  258. position: fixed;
  259. left: 0;
  260. right: 0;
  261. bottom: 62rpx;
  262. text {
  263. font-size: 26rpx;
  264. color: #999;
  265. }
  266. }
  267. .codemodal {
  268. padding: 40rpx;
  269. box-sizing: border-box;
  270. .buttom {
  271. width: 100%;
  272. padding: 19rpx;
  273. box-sizing: border-box;
  274. background-color: #FDE935;
  275. border-radius: 45rpx;
  276. font-weight: bold;
  277. font-size: 36rpx;
  278. color: #1f1f1f;
  279. }
  280. }
  281. .sendcode {
  282. font-size: 28rpx;
  283. color: #F9E000;
  284. }
  285. .u-page__code-text {
  286. padding: 4rpx 18rpx;
  287. background: rgba(253, 233, 53, 0.2);
  288. border-radius: 6rpx 6rpx 6rpx 6rpx;
  289. border: 1rpx solid #FDE935;
  290. color: #333333;
  291. font-size: 26rpx;
  292. }
  293. .btn {
  294. margin: 60rpx 75rpx 0;
  295. box-sizing: border-box;
  296. background: #FDE935;
  297. border-radius: 58rpx 58rpx 58rpx 58rpx;
  298. padding: 20rpx;
  299. box-sizing: border-box;
  300. font-weight: bold;
  301. }
  302. </style>