account-login.vue 4.7 KB

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