index.vue 5.7 KB

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