login.vue 5.9 KB

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