account-login.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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="商编" prop="tenantId" label-width="150">
  14. <u-input :border="false" placeholder="请输入商编" v-model="form.tenantId" ></u-input>
  15. </u-form-item>
  16. <u-form-item label="账号" prop="username" label-width="150">
  17. <u-input :border="false" placeholder="请输入账号" v-model="form.username" ></u-input>
  18. </u-form-item>
  19. <u-form-item label="密码" prop="password" label-width="150">
  20. <u-input :border="false" placeholder="请输入密码" type="password" v-model="form.password"></u-input>
  21. </u-form-item>
  22. </u-form>
  23. </view>
  24. <view style="width: 86%;margin-top: 120rpx;">
  25. <view @click="login" class="btn cu-btn round" style="width:100%;height: 90rpx;font-size: 36rpx;">
  26. 立即登录
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import md5Libs from "uview-ui/libs/function/md5";
  34. export default {
  35. data() {
  36. return {
  37. customStyle:{
  38. 'backgroundColor':'#d18c42',
  39. 'color':'#ffffff'
  40. },
  41. form:{
  42. tenantId:'',
  43. username:'',
  44. password:''
  45. },
  46. rules: {
  47. tenantId: [
  48. {
  49. required: true,
  50. message: '请输入商编',
  51. trigger: ['change','blur'],
  52. }
  53. ],
  54. username: [
  55. {
  56. required: true,
  57. message: '请输入账号',
  58. trigger: ['change','blur'],
  59. }
  60. ],
  61. password: [
  62. {
  63. required: true,
  64. message: '请输入密码',
  65. trigger: ['change','blur'],
  66. }
  67. ],
  68. }
  69. }
  70. },
  71. onReady() {
  72. this.$refs.uForm.setRules(this.rules);
  73. },
  74. onLoad() {
  75. if (this.$cache.get('token')) {
  76. uni.reLaunch({
  77. url:"/pages/index/index"
  78. })
  79. }
  80. },
  81. methods: {
  82. login() {
  83. this.$refs.uForm.validate(valid => {
  84. if (valid) {
  85. this.$dialog.showLoading('登录中..')
  86. setTimeout(()=>{
  87. this.doLogin()
  88. },500)
  89. }
  90. });
  91. },
  92. async doLogin(){
  93. let params={
  94. tenantId:this.form.tenantId,
  95. username:this.form.username,
  96. password:md5Libs.md5(this.form.password)
  97. }
  98. this.$api.system.login(params).then(res=>{
  99. if (this.$isNotEmpty(res.access_token)) {
  100. this.cacheToken(res)
  101. uni.redirectTo({
  102. url:"../index/index"
  103. })
  104. }
  105. })
  106. },
  107. cacheToken(data){
  108. let tokenInfo={
  109. accessToken:data.access_token,
  110. //提前200秒过期
  111. expiresIn:new Date().getTime() + (data.expires_in - 200) * 1000,
  112. refreshToken:data.refresh_token,
  113. tenantId:data.tenant_id,
  114. nickName:data.nick_name
  115. }
  116. this.$cache.put('token',data.access_token)
  117. this.$cache.put("tokenInfo",tokenInfo)
  118. },
  119. }
  120. }
  121. </script>
  122. <style>
  123. page{
  124. background-color: #FFFFFF;
  125. }
  126. </style>
  127. <style lang="scss" scoped>
  128. $color:#d18c42;
  129. page{
  130. background-color: #FFFFFF;
  131. }
  132. .btn{
  133. background-color: $color;
  134. color:#FFFFFF;
  135. }
  136. .bg{
  137. z-index: 99;
  138. height: 440rpx;
  139. width: 440rpx;
  140. position: absolute;
  141. right: -240rpx;
  142. top: -240rpx;
  143. background-color: #d18c42;
  144. border-radius: 50%;
  145. box-shadow: 0rpx 0rpx 50rpx #c5803b;
  146. }
  147. .bg1{
  148. height: 500rpx;
  149. width: 500rpx;
  150. position: absolute;
  151. right: -240rpx;
  152. top: -240rpx;
  153. background-color: #d18c42;
  154. border-radius: 50%;
  155. box-shadow: #c6813b;
  156. }
  157. .content{
  158. height: 84vh;
  159. display: flex;
  160. flex-direction: column;
  161. justify-content: center;
  162. align-items: center;
  163. .top{
  164. display: flex;
  165. .logo{
  166. background-color: $color;
  167. width: 160rpx;
  168. height: 160rpx;
  169. border-radius: 40rpx;
  170. display: flex;
  171. justify-content: center;
  172. align-items: center;
  173. image{
  174. width: 100rpx;
  175. height: 100rpx;
  176. }
  177. }
  178. .title{
  179. margin-right: 20rpx;
  180. display: flex;
  181. flex-direction: column;
  182. text-align: left;
  183. text:first-child{
  184. font-size: 46rpx;
  185. color: #000;
  186. margin-bottom: 20rpx;
  187. }
  188. text:last-child{
  189. font-size: 28rpx;
  190. color: #7f7f7f;
  191. }
  192. }
  193. }
  194. }
  195. </style>