index.vue 5.7 KB

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