account-login.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view style="position: relative;">
  3. <block >
  4. <view class="bg"></view>
  5. <view class="bg1"></view>
  6. <view class="content">
  7. <view class="top">
  8. <view class="logo">
  9. <image src="@/static/icon/logo2.png" mode=""></image>
  10. </view>
  11. </view>
  12. <view style="width: 76%;margin-top: 30rpx;">
  13. <u-form :model="form" :error-type="['message']" ref="uForm">
  14. <u-form-item label-position="top" label="账号" prop="phone" label-width="150">
  15. <u-input :border="false" placeholder="请输入账号" v-model="form.phone" type="number"></u-input>
  16. </u-form-item>
  17. <u-form-item label-position="top" label="密码" prop="password" label-width="150">
  18. <u-input :border="false" placeholder="请输入登录密码" type="password" v-model="form.password">
  19. </u-input>
  20. </u-form-item>
  21. </u-form>
  22. <view class="text-right margin-top-10 text-sm">
  23. <text @click="$jump('/pages/login/login')"
  24. style="margin-left: 20rpx;">手机号快捷登录</text>
  25. </view>
  26. </view>
  27. <view style="width: 86%;margin-top: 120rpx;">
  28. <view @click="login" class="btn cu-btn round" style="width:100%;height: 90rpx;font-size: 36rpx;">
  29. 立即登录
  30. </view>
  31. <view class="flex justify-between text-sm" style="margin: 30rpx 30rpx 0;">
  32. <text @click="$jump('/pages/login/forget')">忘记密码</text>
  33. <text @click="$jump('/pages/login/register')">注册账号</text>
  34. </view>
  35. </view>
  36. </view>
  37. </block>
  38. <toast ref="toast" ></toast>
  39. <loading ref="loading" type="3" />
  40. </view>
  41. </template>
  42. <script>
  43. import md5Libs from "uview-ui/libs/function/md5";
  44. export default {
  45. data() {
  46. return {
  47. loading:true,
  48. customStyle: {
  49. 'backgroundColor': '#d18c42',
  50. 'color': '#ffffff'
  51. },
  52. form: {
  53. type: 'SHOP',
  54. phone: '',
  55. password: ''
  56. },
  57. rules: {
  58. phone: [{
  59. required: true,
  60. message: '请输入账号',
  61. trigger: ['change', 'blur'],
  62. }, {
  63. message: '手机号码不正确',
  64. trigger: ['change', 'blur'],
  65. validator: (rule, value, callback) => {
  66. return this.$u.test.mobile(value);
  67. },
  68. }],
  69. password: [{
  70. required: true,
  71. message: '请输入密码',
  72. trigger: ['change', 'blur'],
  73. }],
  74. }
  75. }
  76. },
  77. onReady() {
  78. this.$refs.uForm.setRules(this.rules);
  79. },
  80. async onLoad(options) {
  81. console.log(this.$u.guid(20));
  82. this.form.phone=options.phone || ''
  83. if (this.$cache.get('phone')) {
  84. this.$refs.loading.show("登录中..")
  85. uni.reLaunch({
  86. url: "/pages/index/index",
  87. success: () => {
  88. this.$refs.loading.hide()
  89. }
  90. })
  91. }
  92. },
  93. methods: {
  94. login() {
  95. this.$refs.uForm.validate(valid => {
  96. if (valid) {
  97. this.loginIn()
  98. }
  99. });
  100. },
  101. async loginIn() {
  102. await this.$mpi.subscribe(this.$tmplIds)
  103. let p = {
  104. type: this.form.type,
  105. phone: this.form.phone,
  106. secret: md5Libs.md5(this.form.password),
  107. }
  108. let res = await this.$api.accout.login(p)
  109. this.cacheToken(res.data)
  110. let shopList = res.data.list
  111. if (!res.success) {
  112. //登录失败
  113. this.$refs.loading.hide()
  114. this.$refs.toast.info(res.msg)
  115. return
  116. }
  117. this.$refs.loading.showLoading('登录中..')
  118. this.loading=true
  119. uni.setStorageSync("phone", this.form.phone)
  120. uni.navigateTo({
  121. url: '/pages/index/index'
  122. })
  123. setTimeout(()=>{
  124. this.loading=false
  125. this.$refs.loading.hide()
  126. this.$refs.toast.info('登录成功')
  127. },1200)
  128. },
  129. cacheToken(data){
  130. let tokenInfo={
  131. accessToken:data.access_token,
  132. //提前200秒过期
  133. expiresIn:new Date().getTime() + (data.expires_in - 200) * 1000,
  134. refreshToken:data.refresh_token,
  135. tenantId:data.tenant_id,
  136. nickName:data.nick_name
  137. }
  138. this.$cache.put('token',data.access_token)
  139. this.$cache.put("tokenInfo",tokenInfo)
  140. },
  141. }
  142. }
  143. </script>
  144. <style>
  145. page {
  146. background-color: #FFFFFF;
  147. }
  148. </style>
  149. <style lang="scss" scoped>
  150. page {
  151. background-color: #FFFFFF;
  152. }
  153. .btn {
  154. background-color: $color;
  155. color: #FFFFFF;
  156. }
  157. .bg {
  158. overflow: hidden;
  159. z-index: 99;
  160. height: 400rpx;
  161. width: 400rpx;
  162. position: absolute;
  163. right: -240rpx;
  164. top: -240rpx;
  165. background-color: $color;
  166. border-radius: 50%;
  167. box-shadow: 0rpx 0rpx 50rpx #e28e3f;
  168. }
  169. .bg1 {
  170. overflow: hidden;
  171. height: 460rpx;
  172. width: 460rpx;
  173. position: absolute;
  174. right: -240rpx;
  175. top: -240rpx;
  176. background-color: $color;
  177. border-radius: 50%;
  178. box-shadow: #c6813b;
  179. }
  180. .content {
  181. height: 84vh;
  182. display: flex;
  183. flex-direction: column;
  184. justify-content: center;
  185. align-items: center;
  186. .top {
  187. display: flex;
  188. .logo {
  189. image {
  190. width: 150rpx;
  191. height: 150rpx;
  192. }
  193. }
  194. .title {
  195. margin-right: 20rpx;
  196. display: flex;
  197. flex-direction: column;
  198. text-align: left;
  199. text:first-child {
  200. font-size: 46rpx;
  201. color: #000;
  202. margin-bottom: 20rpx;
  203. }
  204. text:last-child {
  205. font-size: 28rpx;
  206. color: #7f7f7f;
  207. }
  208. }
  209. }
  210. }
  211. </style>