login.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <view class="">
  3. <view id="box">
  4. <view id="top" class="">
  5. <view class="top_le"></view>
  6. <view class="top_ri"></view>
  7. </view>
  8. <view class="title">
  9. <view style="font-size: 28px!important;">盐都区工信局
  10. <br>办公自动化平台
  11. </view>
  12. </view>
  13. <view class="login-form">
  14. <u--form :model="inputForm" labelWidth="100px" labelPosition="left" :rules="rules" ref="uForm"
  15. :labelStyle="{'font-size':'20px'}">
  16. <u-form-item label="用户名" borderBottom prop="username">
  17. <view style="position: relative;">
  18. <u-input v-model="inputForm.username" @blur="onBlur" @input="getname" @focus="getname"></u-input>
  19. <remember :topPosition="40" :show="isAccount" :list="currentAccounts"
  20. @getAccount="getAccount"></remember>
  21. </view>
  22. </u-form-item>
  23. <u-form-item label="密码" borderBottom prop="password">
  24. <u-input password v-model="inputForm.password" />
  25. </u-form-item>
  26. <u-form-item>
  27. <u-checkbox-group :labelDisabled="true" v-model="account">
  28. <u-checkbox label="记住账号" name="1">
  29. </u-checkbox>
  30. </u-checkbox-group>
  31. </u-form-item>
  32. </u--form>
  33. </view>
  34. <view class="but">
  35. <u-button type="primary" shape="circle" color="linear-gradient(90deg, #1989FA, #19C2FA)"
  36. @click="bindLogin" text="登录"></u-button>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import * as $auth from "@/common/auth.js"
  43. import loginService from "@/api/auth/loginService"
  44. import {
  45. mapActions
  46. } from 'vuex'
  47. import remember from "./remember.vue"
  48. export default {
  49. data() {
  50. return {
  51. isfocus: false,
  52. captchaImg: '',
  53. accounts: [],
  54. currentAccounts: [],
  55. account: [],
  56. isAccount: false,
  57. isrember: [],
  58. inputForm: {
  59. 'username': '',
  60. 'password': '',
  61. 'code': '',
  62. 'uuid': ''
  63. },
  64. rules: {
  65. username: [{
  66. required: true,
  67. message: '请输入用户名',
  68. trigger: ['blur', 'change']
  69. }],
  70. password: [{
  71. required: true,
  72. message: '请输入密码',
  73. trigger: ['blur', 'change']
  74. }],
  75. code: [{
  76. required: true,
  77. message: '请输入验证码',
  78. trigger: ['blur', 'change']
  79. }]
  80. }
  81. }
  82. },
  83. components: {
  84. remember
  85. },
  86. created() {
  87. this.getCaptcha()
  88. if (uni.getStorageSync("accounts")) {
  89. this.accounts = JSON.parse(uni.getStorageSync("accounts"))
  90. this.currentAccounts = JSON.parse(uni.getStorageSync("accounts"))
  91. }
  92. },
  93. methods: {
  94. ...mapActions(['refreshUserInfo']),
  95. // 登录
  96. bindLogin() {
  97. /**
  98. * 客户端对账号信息进行一些必要的校验。
  99. * 实际开发中,根据业务需要进行处理,这里仅做示例。
  100. */
  101. this.$refs.uForm.validate().then(res => {
  102. loginService.login(this.inputForm).then((data) => {
  103. this.$store.commit('SET_TOKEN', data.token);
  104. if (this.account.length > 0) {
  105. let item = {
  106. loginName: this.inputForm.username,
  107. password: this.inputForm.password
  108. }
  109. this.accounts.push(item)
  110. uni.setStorageSync("accounts", JSON.stringify(this.accounts))
  111. }
  112. this.refreshUserInfo();
  113. uni.reLaunch({
  114. url: '../index/index',
  115. });
  116. }).catch(e => {
  117. uni.showToast({
  118. title: e.data
  119. })
  120. this.getCaptcha()
  121. })
  122. })
  123. },
  124. // 获取验证码
  125. getCaptcha() {
  126. loginService.getCode().then((data) => {
  127. this.captchaImg = 'data:image/gif;base64,' + data.codeImg
  128. this.inputForm.uuid = data.uuid
  129. })
  130. },
  131. // 筛选信息
  132. getname(val) {
  133. this.currentAccounts = this.accounts
  134. if (this.accounts == '') {
  135. this.isAccount = false
  136. } else {
  137. this.currentAccounts = this.currentAccounts.filter(item => item.loginName.includes(this.inputForm
  138. .username))
  139. if (this.currentAccounts.length > 0) {
  140. this.isAccount = true
  141. } else {
  142. this.isAccount = false
  143. }
  144. }
  145. },
  146. // 获取选择的账号信息
  147. getAccount(item) {
  148. if (this.inputForm.username != item.loginName) {
  149. this.inputForm.username = item.loginName
  150. }
  151. this.inputForm.password = item.password
  152. this.isAccount = false
  153. },
  154. // 失焦关闭
  155. onBlur(){
  156. setTimeout(()=>{
  157. this.isAccount = false
  158. },300)
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. #box {
  165. position: relative;
  166. width: 100vw;
  167. overflow: hidden;
  168. }
  169. .title {
  170. position: absolute;
  171. top: 15vh;
  172. width: 100vw;
  173. text-align: center;
  174. font-size: 28rpx;
  175. color: #198bfa;
  176. }
  177. .title view:nth-child(1) {
  178. height: 54px;
  179. font-size: 56rpx;
  180. font-family: PingFang SC;
  181. font-weight: bold;
  182. text-shadow: 0px 2px 24px rgba(58, 199, 118, 0.4);
  183. }
  184. .title view:nth-child(2) {
  185. font-size: 32rpx;
  186. font-family: PingFang SC;
  187. font-weight: 500;
  188. color: #198BFA;
  189. margin-top: 5vw;
  190. }
  191. #top {
  192. width: 100vw;
  193. height: 40vh;
  194. position: relative;
  195. }
  196. .top_ri {
  197. width: 100vw;
  198. height: 100vw;
  199. background: linear-gradient(141deg, #19C0FA 0%, #198BFA 100%);
  200. opacity: 0.1;
  201. border-radius: 50%;
  202. position: absolute;
  203. right: -47vw;
  204. top: -37vw;
  205. }
  206. .top_le {
  207. width: 100vw;
  208. height: 100vw;
  209. background: linear-gradient(141deg, #19C0FA 0%, #198BFA 100%);
  210. opacity: 0.1;
  211. border-radius: 50%;
  212. position: absolute;
  213. left: -34vw;
  214. top: -54vw;
  215. }
  216. .inp {
  217. padding-left: 5vw;
  218. position: relative;
  219. top: -4vh;
  220. }
  221. .inp text {
  222. font-size: 36rpx;
  223. font-family: PingFang SC;
  224. font-weight: 500;
  225. color: #333333;
  226. margin-left: 5px;
  227. }
  228. .but {
  229. padding-left: 50rpx;
  230. padding-right: 50rpx;
  231. margin-top: 60rpx;
  232. }
  233. .but * {
  234. font-size: 40rpx !important;
  235. }
  236. .fot {
  237. width: 100vw;
  238. height: 26px;
  239. text-align: center;
  240. font-size: 28rpx;
  241. font-family: PingFang SC;
  242. font-weight: 500;
  243. color: #8E8E8E;
  244. margin-top: 20px;
  245. }
  246. .login-form {
  247. padding-left: 100rpx;
  248. padding-right: 30rpx;
  249. }
  250. </style>