index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view class="login-box">
  3. <image class="logoImg" src="@/static/logo.png"></image>
  4. <image class="loginImg" src="@/static/login.png"></image>
  5. <view class="loginContent">
  6. <p class="title">企业数字应用平台</p>
  7. <uni-forms :modelValue="formData" :rules="rules" ref="form">
  8. <!-- <uni-forms-item name="enterpriseCode">
  9. <uni-easyinput type="text" prefixIcon="vip-filled" v-model="formData.enterpriseCode"
  10. placeholder="请输入企业简称" />
  11. </uni-forms-item> -->
  12. <uni-forms-item name="username">
  13. <uni-easyinput type="text" prefixIcon="person" v-model="formData.username" placeholder="请输入用户名" />
  14. </uni-forms-item>
  15. <uni-forms-item name="password">
  16. <uni-easyinput type="password" prefixIcon="locked" v-model="formData.password"
  17. placeholder="请输入密码" />
  18. </uni-forms-item>
  19. <!-- <view class="form-code">
  20. <view class="input-box">
  21. <uni-forms-item name="code">
  22. <uni-easyinput type="text" prefixIcon="locked-filled" v-model="formData.code"
  23. placeholder="请输入验证码" />
  24. </uni-forms-item>
  25. </view>
  26. <view class="img-box">
  27. <image :src="codeUrl" class="img_code" @click="getImgCode"></image>
  28. </view>
  29. </view> -->
  30. </uni-forms>
  31. <button type="primary" class="loginBtn" @click="login">登 录</button>
  32. </view>
  33. <u-toast ref="uToast"></u-toast>
  34. </view>
  35. </template>
  36. <script>
  37. import $baseUrl from '@/https/index.js';
  38. export default {
  39. data() {
  40. return {
  41. formData: {
  42. enterpriseCode: '',
  43. username: '',
  44. password: '',
  45. code: '',
  46. uuid: ''
  47. },
  48. rules: {
  49. // enterpriseCode: {
  50. // rules: [{
  51. // required: true,
  52. // errorMessage: '请输入企业简称',
  53. // }, ],
  54. // },
  55. username: {
  56. rules: [{
  57. required: true,
  58. errorMessage: '请输入用户名',
  59. }, ],
  60. },
  61. password: {
  62. rules: [{
  63. required: true,
  64. errorMessage: '请输入密码',
  65. }, ],
  66. },
  67. // code: {
  68. // rules: [{
  69. // required: true,
  70. // errorMessage: '请输入验证码',
  71. // }, ],
  72. // }
  73. },
  74. codeUrl: '',
  75. }
  76. },
  77. onShow() {
  78. // this.getImgCode()
  79. uni.hideLoading()
  80. const enterpriseCode = uni.getStorageSync('enterpriseCode') // 获取缓存中的企业简称
  81. if (enterpriseCode) {
  82. this.formData.enterpriseCode = enterpriseCode
  83. }
  84. const username = uni.getStorageSync('username') // 获取缓存中的用户名
  85. if (username) {
  86. this.formData.username = username
  87. }
  88. const password = uni.getStorageSync('password') // 获取缓存中的密码
  89. if (password) {
  90. this.formData.password = password
  91. }
  92. },
  93. methods: {
  94. getImgCode() {
  95. const url = '/captchaImage'
  96. uni.request({
  97. method: 'get',
  98. url: $baseUrl.url + url,
  99. })
  100. .then((response) => {
  101. console.log(response,102);
  102. const res = response[1].data
  103. if (res.code === 200) {
  104. this.codeUrl = 'data:image/gif;base64,' + res.img
  105. this.formData.uuid = res.uuid
  106. }
  107. }).catch((reject) => {
  108. console.log('请求失败')
  109. })
  110. },
  111. // 登录
  112. login(form) {
  113. this.$refs.form.validate().then(res => {
  114. const url = '/login'
  115. uni.request({
  116. method: 'post',
  117. url: $baseUrl.url + url,
  118. data: this.formData,
  119. })
  120. .then((response) => {
  121. const res = response[1].data
  122. if (res.code === 200) {
  123. uni.setStorageSync('token', res.token);
  124. uni.setStorageSync('enterpriseCode', this.formData.enterpriseCode);
  125. uni.setStorageSync('username', this.formData.username);
  126. uni.setStorageSync('password', this.formData.password);
  127. uni.showLoading({
  128. title: '登录中...'
  129. });
  130. setTimeout(function() {
  131. uni.hideLoading();
  132. uni.reLaunch({
  133. url: "/pages/index/index"
  134. })
  135. }, 2000);
  136. } else {
  137. this.$refs.uToast.show({
  138. type: 'error',
  139. message: res.msg,
  140. })
  141. this.getImgCode()
  142. this.formData.code = ''
  143. }
  144. }).catch((reject) => {
  145. console.log('请求失败')
  146. })
  147. }).catch(err => {
  148. console.log('表单错误信息:', err);
  149. })
  150. },
  151. }
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. .login-box {
  156. background-color: #fff;
  157. height: 100%;
  158. }
  159. .logoImg{
  160. z-index: 1;
  161. width: 320rpx;
  162. height: 80rpx;
  163. position: absolute;
  164. top: 10rpx;
  165. left: 10rpx;
  166. }
  167. .loginImg {
  168. width: 100%;
  169. }
  170. .loginContent {
  171. width: 80%;
  172. margin: auto;
  173. text-align: center;
  174. .title {
  175. font-size: 44rpx;
  176. font-weight: bold;
  177. color: #3f7fff;
  178. margin: 20rpx 0 60rpx 0;
  179. }
  180. /deep/.uni-forms-item .is-required {
  181. display: none;
  182. }
  183. /deep/.uni-forms-item__label {
  184. padding: 0;
  185. }
  186. /deep/.uni-easyinput__content.is-input-border {
  187. height: 90rpx;
  188. border-radius: 50rpx;
  189. padding: 20rpx;
  190. }
  191. .loginBtn {
  192. font-size: 38rpx;
  193. height: 100rpx;
  194. line-height: 100rpx;
  195. border-radius: 50rpx;
  196. width: 100%;
  197. background-image: linear-gradient(to right, #3f7fff, #5cb7ec);
  198. border: none;
  199. margin-top: 40rpx;
  200. }
  201. }
  202. .form-code {
  203. display: flex;
  204. justify-content: space-between;
  205. .input-box {
  206. width: 60%;
  207. }
  208. .img-box {
  209. width: 40%;
  210. height: 80rpx;
  211. margin-left: 2%;
  212. .img_code {
  213. width: 100%;
  214. height: 100%;
  215. }
  216. }
  217. }
  218. </style>