login.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="bigback">
  3. <image src="https://cczdsz.cn/app/images/42ad4e72a9bb4f08ac613933c04c679a.png" mode="" class="background"></image>
  4. <view class="title">
  5. <image src="https://cczdsz.cn/app/images/logo.png" mode="" class="logo" style="width: 30px;height: 30px;"></image>
  6. <view class="font-sixty-four" style="color:dodgerblue;font-weight:bold;font-size: 14px;">
  7. 长春贞达市政巡线调压、抢险维修管理平台
  8. </view>
  9. <image src="https://cczdsz.cn/app/images/41743f2fb9b54c8e87e1168bb094505b.png" mode="" class="logo"></image>
  10. </view>
  11. <view>
  12. <view class="align-items margin">
  13. <image src="https://cczdsz.cn/app/images//zh.png" mode="" class="img"></image>
  14. <input type="text" placeholder="账号" placeholder-class="font-forty-eight"
  15. class="input font-forty-eight" v-model="form.number" />
  16. </view>
  17. <view class="align-items margin">
  18. <image src="https://cczdsz.cn/app/images//mm.png" mode="" class="img"></image>
  19. <input type="password" placeholder="密码" placeholder-class="font-forty-eight"
  20. class="input font-forty-eight" v-model="form.password" />
  21. </view>
  22. </view>
  23. <view class="remember">
  24. <u-checkbox-group @change="checkboxGroupChange">
  25. <u-checkbox
  26. @change="checkboxChange"
  27. v-model="item.checked"
  28. v-for="(item, index) in list" :key="index"
  29. :name="item.name"
  30. >{{item.name}}</u-checkbox>
  31. </u-checkbox-group>
  32. </view>
  33. <view @click="login()">
  34. <button class="background-color1 white font-forty-eight btn">登录</button>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import service from '@/api/index.js'
  40. export default {
  41. data() {
  42. return {
  43. form: {
  44. number: '',
  45. password: ''
  46. },
  47. list:[
  48. {
  49. name: '记住密码',
  50. checked: true,
  51. disabled: false
  52. }
  53. ],
  54. flag: true,
  55. }
  56. },
  57. onLoad() {
  58. const HCnumber = uni.getStorageSync('HCnumber');
  59. const HCpassword = uni.getStorageSync('HCpassword');//缓存的密码
  60. if(HCnumber && HCpassword){
  61. this.form.number = HCnumber;
  62. this.form.password = HCpassword;
  63. }
  64. },
  65. methods: {
  66. login() {
  67. if (this.form.number === '') {
  68. this.$UTILS.showPrompt('请输入工号!')
  69. } else if (this.form.password === '') {
  70. this.$UTILS.showPrompt('请输入密码!')
  71. } else {
  72. let _this = this;
  73. let param = {
  74. jobNum: _this.form.number,
  75. password: _this.form.password
  76. }
  77. if(_this.flag){
  78. uni.setStorageSync('HCnumber', _this.form.number);
  79. uni.setStorageSync('HCpassword', _this.form.password);
  80. }else{
  81. uni.removeStorageSync('HCnumber');
  82. uni.removeStorageSync('HCpassword');
  83. }
  84. service.login(param).then(res => {
  85. console.log('res', res.token)
  86. uni.setStorage({
  87. key: 'token',
  88. data: res.token,
  89. success: (res) => {
  90. console.log('登陆成功res',res)
  91. console.log('登陆成功')
  92. this.$UTILS.showPrompt('登录成功!')
  93. setTimeout(()=>{
  94. console.log('跳')
  95. uni.switchTab({
  96. url:'/pages/index/index'
  97. })
  98. // uni.navigateTo({
  99. // url:'/pages/noLogin/roadSection/roadSection?type=2'
  100. // })
  101. console.log('跳')
  102. },2000)
  103. },
  104. fail: (e) => {
  105. console.log(e)
  106. }
  107. })
  108. })
  109. }
  110. },
  111. checkboxChange(e) {
  112. this.flag = e.value;
  113. },
  114. // 选中任一checkbox时,由checkbox-group触发
  115. checkboxGroupChange(e) {
  116. if(e.length > 0){
  117. uni.setStorageSync('HCnumber', this.form.number);
  118. uni.setStorageSync('HCpassword', this.form.password);
  119. }else{
  120. uni.removeStorageSync('HCnumber');
  121. uni.removeStorageSync('HCpassword');
  122. }
  123. },
  124. }
  125. }
  126. </script>
  127. <style lang="scss">
  128. .background {
  129. z-index: -1;
  130. width: 100%;
  131. height: 610rpx;
  132. }
  133. .title {
  134. display: flex;
  135. margin: 20rpx 0;
  136. .logo {
  137. width: 690rpx;
  138. height: 62rpx;
  139. margin: -6px auto;
  140. }
  141. }
  142. .margin {
  143. margin:20rpx;
  144. background: #f1f7ff;
  145. border: solid 1rpx #84b7ff;
  146. border-radius: 80rpx;
  147. padding: 0 50rpx;
  148. width: 86%;
  149. margin: 26rpx auto;
  150. .img {
  151. width: 70rpx;
  152. height: 60rpx;
  153. }
  154. .input {
  155. width: 100%;
  156. height: 75rpx;
  157. padding: 20rpx 20rpx;
  158. font-size: 32rpx;
  159. color: #999999;
  160. }
  161. }
  162. .remember{
  163. width: 100%;
  164. height: 80rpx;
  165. line-height: 80rpx;
  166. padding-left: 80rpx;
  167. letter-spacing: 2rpx;
  168. }
  169. .btn {
  170. width: 86%;
  171. margin: 0rpx auto 0;
  172. background: linear-gradient(45deg, #55bafe, #3072ff);
  173. border-radius: 72rpx;
  174. box-shadow: 0rpx 0rpx 20rpx #3f8fff;
  175. }
  176. </style>