index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <!-- #ifdef H5 -->
  2. <template>
  3. <view v-if="bindPhone">
  4. <form @submit="editPwd" report-submit='true'>
  5. <view class="ChangePassword">
  6. <view class="list">
  7. <view class="item">
  8. <input type='number' :placeholder='$t(`请输入手机号`)' placeholder-class='placeholder'
  9. v-model="phone"></input>
  10. </view>
  11. <view class="item acea-row row-between-wrapper">
  12. <input type='number' :placeholder='$t(`填写验证码`)' placeholder-class='placeholder' class="codeIput"
  13. v-model="captcha"></input>
  14. <button class="code font-color" :class="disabled === true ? 'on' : ''" :disabled='disabled'
  15. @click="code">
  16. {{ text }}
  17. </button>
  18. </view>
  19. </view>
  20. <button form-type="submit" class="confirmBnt bg-color">{{$t(`确认绑定`)}}</button>
  21. </view>
  22. </form>
  23. <Verify @success="success" :captchaType="'blockPuzzle'" :imgSize="{ width: '330px', height: '155px' }"
  24. ref="verify"></Verify>
  25. </view>
  26. <view class="lottie-bg" v-else>
  27. <view id="lottie">
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import wechat from "@/libs/wechat";
  33. import sendVerifyCode from "@/mixins/SendVerifyCode";
  34. import {
  35. getUserInfo
  36. } from "@/api/user";
  37. import {
  38. WX_AUTH,
  39. STATE_KEY,
  40. LOGINTYPE,
  41. BACK_URL
  42. } from '@/config/cache';
  43. import {
  44. silenceAuth
  45. } from '@/api/public';
  46. import {
  47. bindingPhone,
  48. verifyCode
  49. } from '@/api/api.js';
  50. import {
  51. registerVerify
  52. } from '@/api/user.js'
  53. import Verify from '../components/verify/index.vue';
  54. export default {
  55. name: "Auth",
  56. components: {
  57. Verify
  58. },
  59. mixins: [sendVerifyCode],
  60. data() {
  61. return {
  62. phone: '',
  63. captcha: '',
  64. key: '',
  65. authKey: '',
  66. scope: '',
  67. bindPhone: false,
  68. };
  69. },
  70. mounted() {
  71. },
  72. onLoad(options) {
  73. let that = this
  74. const {
  75. code,
  76. state,
  77. scope
  78. } = options;
  79. if (scope === 'snsapi_base') {
  80. this.url = options.url || options.back_url || '';
  81. let spread = this.$Cache.get("spread");
  82. let loginType = this.$Cache.get(LOGINTYPE);
  83. // silenceAuth({
  84. // code: options.code || '',
  85. // spread: spread
  86. // }).then(res => {
  87. // if (res.data.key !== undefined) {
  88. // this.bindPhone = true;
  89. // this.authKey = res.data.key;
  90. // } else {
  91. // this.$store.commit("LOGIN", {
  92. // token: res.data.token,
  93. // time: parseInt(res.data.expires_time) - this.$Cache.time()
  94. // });
  95. // this.$Cache.set(WX_AUTH, options.code);
  96. // this.$Cache.clear(STATE_KEY);
  97. // loginType && this.$Cache.clear(LOGINTYPE);
  98. // location.href = decodeURIComponent(
  99. // decodeURIComponent(options.back_url)
  100. // );
  101. // }
  102. // })
  103. } else {
  104. wechat.auth(code, state).then(() => {
  105. location.href = decodeURIComponent(
  106. decodeURIComponent(options.back_url)
  107. );
  108. getUserInfo().then(res => {
  109. that.$store.commit("SETUID", res.data.uid);
  110. });
  111. }).catch(() => {
  112. location.replace("/");
  113. });
  114. }
  115. },
  116. methods: {
  117. editPwd: function() {
  118. let that = this;
  119. if (!that.phone) {
  120. return that.$util.Tips({
  121. title: that.$t(`请输入手机号`)
  122. });
  123. }
  124. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) {
  125. return that.$util.Tips({
  126. title: that.$t(`请输入正确的手机号码`)
  127. });
  128. }
  129. if (!that.captcha) {
  130. return that.$util.Tips({
  131. title: that.$t(`填写验证码`)
  132. });
  133. }
  134. bindingPhone({
  135. phone: that.phone,
  136. captcha: that.captcha,
  137. key: that.authKey
  138. }).then(res => {
  139. let time = res.data.expires_time - this.$Cache.time();
  140. this.$store.commit('LOGIN', {
  141. token: res.data.token,
  142. time: time
  143. });
  144. if (this.url && this.url.indexOf('http') !== -1) {
  145. location.href = this.url;
  146. } else {
  147. return that.$util.Tips({
  148. title: this.$t(`绑定成功`),
  149. icon: 'success'
  150. }, {
  151. tab: 4,
  152. url: '/pages/index/index'
  153. });
  154. }
  155. }).catch(err => {
  156. return that.$util.Tips({
  157. title: err
  158. });
  159. })
  160. },
  161. /**
  162. * 发送验证码
  163. *
  164. */
  165. code() {
  166. let that = this;
  167. if (!that.phone) return that.$util.Tips({
  168. title: that.$t(`请输入手机号`)
  169. });
  170. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  171. title: that.$t(`请输入正确的手机号码`)
  172. });
  173. this.$refs.verify.show()
  174. },
  175. success(data) {
  176. this.$refs.verify.hide()
  177. verifyCode().then(res => {
  178. registerVerify({
  179. phone: that.phone,
  180. type: 'reset',
  181. key: res.data.key,
  182. captchaType: 'blockPuzzle',
  183. captchaVerification: data.captchaVerification
  184. }).then(res => {
  185. this.sendCode()
  186. that.$util.Tips({
  187. title: res.msg
  188. });
  189. }).catch(err => {
  190. return that.$util.Tips({
  191. title: err
  192. });
  193. });
  194. });
  195. },
  196. }
  197. };
  198. </script>
  199. <style scoped lang="scss">
  200. page {
  201. background-color: #fff !important;
  202. }
  203. .ChangePassword .phone {
  204. font-size: 32rpx;
  205. font-weight: bold;
  206. text-align: center;
  207. margin-top: 55rpx;
  208. }
  209. .ChangePassword .list {
  210. width: 580rpx;
  211. margin: 53rpx auto 0 auto;
  212. }
  213. .ChangePassword .list .item {
  214. width: 100%;
  215. height: 110rpx;
  216. border-bottom: 2rpx solid #f0f0f0;
  217. }
  218. .ChangePassword .list .item input {
  219. width: 100%;
  220. height: 100%;
  221. font-size: 32rpx;
  222. }
  223. .ChangePassword .list .item .placeholder {
  224. color: #b9b9bc;
  225. }
  226. .ChangePassword .list .item input.codeIput {
  227. width: 340rpx;
  228. }
  229. .ChangePassword .list .item .code {
  230. font-size: 32rpx;
  231. background-color: #fff;
  232. }
  233. .ChangePassword .list .item .code.on {
  234. color: #b9b9bc !important;
  235. }
  236. .ChangePassword .confirmBnt {
  237. font-size: 32rpx;
  238. width: 580rpx;
  239. height: 90rpx;
  240. border-radius: 45rpx;
  241. color: #fff;
  242. margin: 92rpx auto 0 auto;
  243. text-align: center;
  244. line-height: 90rpx;
  245. }
  246. .lottie-bg {
  247. position: fixed;
  248. left: 0;
  249. top: 0;
  250. background-color: #fff;
  251. width: 100%;
  252. height: 100%;
  253. z-index: 999;
  254. display: flex;
  255. align-items: center;
  256. justify-content: center;
  257. }
  258. #lottie {
  259. display: block;
  260. width: 100%;
  261. height: 100%;
  262. display: flex;
  263. align-items: center;
  264. justify-content: center;
  265. overflow: hidden;
  266. transform: translate3d(0, 0, 0);
  267. margin: auto;
  268. image {
  269. width: 200rpx;
  270. height: 200rpx;
  271. }
  272. }
  273. </style>
  274. <!-- #endif -->