index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. });
  96. }).catch(() => {
  97. location.replace("/");
  98. });
  99. }
  100. },
  101. methods: {
  102. editPwd: function() {
  103. let that = this;
  104. if (!that.phone) {
  105. return that.$util.Tips({
  106. title: '请填写手机号码!'
  107. });
  108. }
  109. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) {
  110. return that.$util.Tips({
  111. title: '请输入正确的手机号码!'
  112. });
  113. }
  114. if (!that.captcha) {
  115. return that.$util.Tips({
  116. title: '请填写验证码'
  117. });
  118. }
  119. bindingPhone({
  120. phone: that.phone,
  121. captcha: that.captcha,
  122. key: this.authKey
  123. }).then(res => {
  124. let time = res.data.expires_time - this.$Cache.time();
  125. this.$store.commit('LOGIN', { token : res.data.token, time : time });
  126. if (this.url && this.url.indexOf('http') !== -1) {
  127. location.href = this.url;
  128. } else {
  129. return that.$util.Tips({
  130. title: '绑定成功!',
  131. icon: 'success'
  132. }, {
  133. tab: 4,
  134. url: '/pages/index/index'
  135. });
  136. }
  137. }).catch(err => {
  138. return that.$util.Tips({
  139. title: err
  140. });
  141. })
  142. },
  143. /**
  144. * 发送验证码
  145. *
  146. */
  147. code() {
  148. let that = this;
  149. if (!that.phone) return that.$util.Tips({
  150. title: '请填写手机号码!'
  151. });
  152. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  153. title: '请输入正确的手机号码!'
  154. });
  155. verifyCode().then(res => {
  156. registerVerify(that.phone, 'reset', res.data.key, that.captcha).then(res => {
  157. that.$util.Tips({
  158. title: res.msg
  159. });
  160. that.sendCode();
  161. }).catch(err => {
  162. return that.$util.Tips({
  163. title: err
  164. });
  165. });
  166. });
  167. }
  168. }
  169. };
  170. </script>
  171. <style scoped lang="scss">
  172. page {
  173. background-color: #fff !important;
  174. }
  175. .ChangePassword .phone {
  176. font-size: 32rpx;
  177. font-weight: bold;
  178. text-align: center;
  179. margin-top: 55rpx;
  180. }
  181. .ChangePassword .list {
  182. width: 580rpx;
  183. margin: 53rpx auto 0 auto;
  184. }
  185. .ChangePassword .list .item {
  186. width: 100%;
  187. height: 110rpx;
  188. border-bottom: 2rpx solid #f0f0f0;
  189. }
  190. .ChangePassword .list .item input {
  191. width: 100%;
  192. height: 100%;
  193. font-size: 32rpx;
  194. }
  195. .ChangePassword .list .item .placeholder {
  196. color: #b9b9bc;
  197. }
  198. .ChangePassword .list .item input.codeIput {
  199. width: 340rpx;
  200. }
  201. .ChangePassword .list .item .code {
  202. font-size: 32rpx;
  203. background-color: #fff;
  204. }
  205. .ChangePassword .list .item .code.on {
  206. color: #b9b9bc !important;
  207. }
  208. .ChangePassword .confirmBnt {
  209. font-size: 32rpx;
  210. width: 580rpx;
  211. height: 90rpx;
  212. border-radius: 45rpx;
  213. color: #fff;
  214. margin: 92rpx auto 0 auto;
  215. text-align: center;
  216. line-height: 90rpx;
  217. }
  218. .lottie-bg {
  219. position: fixed;
  220. left: 0;
  221. top: 0;
  222. background-color: #fff;
  223. width: 100%;
  224. height: 100%;
  225. z-index: 999;
  226. display: flex;
  227. align-items: center;
  228. justify-content: center;
  229. }
  230. #lottie {
  231. display: block;
  232. width: 100%;
  233. height: 100%;
  234. display: flex;
  235. align-items: center;
  236. justify-content: center;
  237. overflow: hidden;
  238. transform: translate3d(0, 0, 0);
  239. margin: auto;
  240. image {
  241. width: 200rpx;
  242. height: 200rpx;
  243. }
  244. }
  245. </style>
  246. <!-- #endif -->