index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <!-- index.wxml -->
  3. <view class="wrap">
  4. <view class="wrap_nr">
  5. <image class="user_thumb" :src="userInfo.thumb"></image>
  6. <view class="user_name">您好,{{ userInfo.nickname }}</view>
  7. <view class="tips">为了您的账户安全,请绑定手机号</view>
  8. <view class="form_wrap">
  9. <view class="form_item">
  10. <view class="item_label">手机号码</view>
  11. <view class="item_file">
  12. <van-field :value="phone" placeholder="请输入手机号码" :border="false" @change="getPhone" />
  13. <button hover-class="none" class="btn_code" :disabled="codeLoading" :loading="codeLoading" @tap="sendCode">{{ codeBtnName }}</button>
  14. </view>
  15. </view>
  16. <view class="form_item">
  17. <view class="item_label">手机验证码</view>
  18. <view class="item_file">
  19. <van-field :value="code" placeholder="请输入手机验证码" :border="false" @change="getPhoneCode" />
  20. </view>
  21. </view>
  22. </view>
  23. <button class="custom_btn" @tap="phoneLogin">登录</button>
  24. </view>
  25. </view>
  26. <!-- loading -->
  27. <!-- <van-overlay show="{{ loading }}" z-index="100">
  28. <van-loading custom-class="custom_loading" />
  29. </van-overlay> -->
  30. </template>
  31. <script>
  32. // index.js
  33. let myPro = require('../../../utils/wxRequest.js');
  34. let util = require('../../../utils/util.js');
  35. export default {
  36. data() {
  37. return {
  38. phone: null,
  39. code: null,
  40. codeLoading: false,
  41. codeBtnName: '获取验证码',
  42. delyTime: 60,
  43. // 两次发验证码间隔时长/秒
  44. // 全局loading
  45. loading: false,
  46. userInfo: {
  47. thumb: '',
  48. nickname: ''
  49. },
  50. store: ''
  51. };
  52. },
  53. onLoad: function (options) {
  54. // Do some initialize when page load.
  55. },
  56. onShow: function () {
  57. // Do something when page show.
  58. let that = this;
  59. that.setData({
  60. userInfo: getApp().globalData.userInfo
  61. }); // console.log('用户信息',that.data.userInfo)
  62. // 店铺
  63. uni.getStorage({
  64. key: 'store',
  65. success: function (res) {
  66. that.setData({
  67. store: JSON.parse(res.data)
  68. });
  69. }
  70. });
  71. },
  72. onReady: function () {
  73. // Do something when page ready.
  74. },
  75. onHide: function () {
  76. // Do something when page hide.
  77. },
  78. onUnload: function () {
  79. // Do something when page close.
  80. },
  81. onPullDownRefresh: function () {
  82. // Do something when pull down.
  83. },
  84. onReachBottom: function () {
  85. // Do something when page reach bottom.
  86. },
  87. onPageScroll: function () {
  88. // Do something when page scroll
  89. },
  90. onResize: function () {
  91. // Do something when page resize
  92. },
  93. methods: {
  94. // 获取输入信息 手机号
  95. getPhone: function (event) {
  96. let that = this;
  97. that.setData({
  98. phone: event.detail
  99. });
  100. },
  101. // 发送验证码
  102. sendCode() {
  103. let that = this;
  104. if (!that.phone || !/^1[3456789]\d{9}$/.test(that.phone)) {
  105. uni.showToast({
  106. title: '手机号有误,请重新填写',
  107. icon: 'none'
  108. });
  109. return;
  110. }
  111. let params = {
  112. phone: that.phone
  113. };
  114. myPro
  115. .wxRequest('user/send/verify-code', 'POST', params)
  116. .then((res) => {
  117. uni.showToast({
  118. title: res.msg,
  119. icon: 'none'
  120. });
  121. that.setData({
  122. codeBtnName: that.delyTime + 's',
  123. delyTime: that.delyTime,
  124. codeLoading: true
  125. });
  126. let s = setInterval(function () {
  127. let dely1 = parseInt(that.delyTime) - 1; // console.log(dely1);
  128. that.setData({
  129. codeBtnName: dely1 + 's',
  130. delyTime: dely1
  131. });
  132. if (dely1 == 0) {
  133. clearInterval(s);
  134. that.setData({
  135. codeBtnName: '获取验证码',
  136. delyTime: that.delyTime,
  137. codeLoading: false
  138. });
  139. }
  140. }, 1000);
  141. })
  142. .catch((err) => {
  143. that.setData({
  144. codeLoading: false
  145. });
  146. console.log('报错信息');
  147. uni.showToast({
  148. title: err,
  149. icon: 'none'
  150. });
  151. });
  152. },
  153. // 获取输入信息 验证码
  154. getPhoneCode: function (event) {
  155. let that = this;
  156. that.setData({
  157. code: event.detail
  158. });
  159. },
  160. // 手机号验证码登录
  161. phoneLogin() {
  162. let that = this;
  163. if (!that.phone || !/^1[3456789]\d{9}$/.test(that.phone)) {
  164. uni.showToast({
  165. title: '手机号有误,请重新填写',
  166. icon: 'none'
  167. });
  168. return;
  169. }
  170. if (!that.code) {
  171. uni.showToast({
  172. title: '请填写验证码',
  173. icon: 'none'
  174. });
  175. return;
  176. }
  177. let params = {
  178. phone: that.phone,
  179. code: that.code,
  180. // 手机号验证码
  181. openid: getApp().globalData.openid,
  182. nickname: getApp().globalData.userInfo.nickname,
  183. thumb: getApp().globalData.userInfo.thumb,
  184. sex: getApp().globalData.userInfo.sex,
  185. store_id: that.store ? that.store.id : 1 // 门店id
  186. };
  187. myPro
  188. .wxRequest('user/mini-login', 'POST', params)
  189. .then((res) => {
  190. // 存下token
  191. getApp().globalData.token = res.result.token;
  192. uni.setStorage({
  193. key: 'token',
  194. data: res.result.token
  195. }); // 存下角色
  196. if (res.result.user.store) {
  197. getApp().globalData.role = 1; // 有店铺,即为门店
  198. }
  199. uni.reLaunch({
  200. url: '/pages/index/index'
  201. });
  202. })
  203. .catch((err) => {
  204. console.log('报错信息', err);
  205. uni.showToast({
  206. title: err,
  207. icon: 'none'
  208. });
  209. });
  210. }
  211. }
  212. };
  213. </script>
  214. <style>
  215. /**index.wxss**/
  216. .wrap_nr {
  217. padding-top: 150rpx;
  218. text-align: center;
  219. }
  220. .user_thumb {
  221. width: 148rpx;
  222. height: 148rpx;
  223. border-radius: 50%;
  224. }
  225. .user_name {
  226. padding-top: 50rpx;
  227. font-size: 40rpx;
  228. color: #333333;
  229. }
  230. .tips {
  231. padding-top: 20rpx;
  232. font-size: 28rpx;
  233. color: rgba(51, 51, 51, 0.54);
  234. }
  235. .custom_btn {
  236. width: 604rpx !important;
  237. height: 90rpx;
  238. padding: 0;
  239. margin: 120rpx 0 0 0;
  240. line-height: unset;
  241. font-weight: normal;
  242. background: #295c56;
  243. border-radius: 45rpx;
  244. font-size: 34rpx;
  245. color: #ffffff;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. }
  250. .form_wrap {
  251. padding: 50rpx 75rpx 0;
  252. }
  253. .form_item {
  254. font-size: 30rpx;
  255. color: #000000;
  256. border-bottom: 1rpx solid rgba(0, 0, 0, 0.2);
  257. padding-top: 70rpx;
  258. }
  259. .form_item .item_label {
  260. text-align: left;
  261. }
  262. .form_item .item_file {
  263. font-size: 28rpx;
  264. display: flex;
  265. align-items: center;
  266. justify-content: space-between;
  267. }
  268. .form_item .item_file van-field {
  269. flex: 1;
  270. }
  271. .form_item .item_file .van-cell {
  272. padding-left: 0;
  273. background: unset;
  274. }
  275. .btn_code {
  276. width: auto !important;
  277. padding: 0;
  278. margin: 0;
  279. font-size: 26rpx;
  280. color: #ed8c17;
  281. background: unset;
  282. line-height: unset;
  283. font-weight: normal;
  284. }
  285. </style>