index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 '@/pages/users/components/verify/verify.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. that.$util.Tips({
  186. title: res.msg
  187. });
  188. }).catch(err => {
  189. return that.$util.Tips({
  190. title: err
  191. });
  192. });
  193. });
  194. },
  195. }
  196. };
  197. </script>
  198. <style scoped lang="scss">
  199. page {
  200. background-color: #fff !important;
  201. }
  202. .ChangePassword .phone {
  203. font-size: 32rpx;
  204. font-weight: bold;
  205. text-align: center;
  206. margin-top: 55rpx;
  207. }
  208. .ChangePassword .list {
  209. width: 580rpx;
  210. margin: 53rpx auto 0 auto;
  211. }
  212. .ChangePassword .list .item {
  213. width: 100%;
  214. height: 110rpx;
  215. border-bottom: 2rpx solid #f0f0f0;
  216. }
  217. .ChangePassword .list .item input {
  218. width: 100%;
  219. height: 100%;
  220. font-size: 32rpx;
  221. }
  222. .ChangePassword .list .item .placeholder {
  223. color: #b9b9bc;
  224. }
  225. .ChangePassword .list .item input.codeIput {
  226. width: 340rpx;
  227. }
  228. .ChangePassword .list .item .code {
  229. font-size: 32rpx;
  230. background-color: #fff;
  231. }
  232. .ChangePassword .list .item .code.on {
  233. color: #b9b9bc !important;
  234. }
  235. .ChangePassword .confirmBnt {
  236. font-size: 32rpx;
  237. width: 580rpx;
  238. height: 90rpx;
  239. border-radius: 45rpx;
  240. color: #fff;
  241. margin: 92rpx auto 0 auto;
  242. text-align: center;
  243. line-height: 90rpx;
  244. }
  245. .lottie-bg {
  246. position: fixed;
  247. left: 0;
  248. top: 0;
  249. background-color: #fff;
  250. width: 100%;
  251. height: 100%;
  252. z-index: 999;
  253. display: flex;
  254. align-items: center;
  255. justify-content: center;
  256. }
  257. #lottie {
  258. display: block;
  259. width: 100%;
  260. height: 100%;
  261. display: flex;
  262. align-items: center;
  263. justify-content: center;
  264. overflow: hidden;
  265. transform: translate3d(0, 0, 0);
  266. margin: auto;
  267. image {
  268. width: 200rpx;
  269. height: 200rpx;
  270. }
  271. }
  272. </style>
  273. <!-- #endif -->