login.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <view>
  3. <u-toast ref="uToast" />
  4. <view class="d-flex f-column a-center top">
  5. <image src="../../static/logo.png" mode=""></image>
  6. <text class="main-color-text f-weight-bold m2">欢迎使用设备管理系统!</text>
  7. </view>
  8. <view class="f-weight-bold name text-center">账号登录</view>
  9. <view class="input">
  10. <input type="text" v-model="userName" placeholder="请输入用户名" placeholder-class="placeholder-class" />
  11. <input type="password" v-model="passWord" placeholder="请输入密码" placeholder-class="placeholder-class" />
  12. </view>
  13. <view class="tip" @tap="forgetPass">
  14. 忘记密码
  15. <text class="mx1">
  16. <u-icon name="question"></u-icon>
  17. </text>
  18. </view>
  19. <view class=" mui-input-row mui-checkbox ">
  20. <checkbox-group @change="checkboxChange">
  21. <checkbox id="chkRem" type="checkbox" :checked="rememberPsw" @tap="rememberPsw = !rememberPsw"
  22. class="RememberCheck">
  23. 记住密码
  24. </checkbox>
  25. </checkbox-group>
  26. </view>
  27. <button class="main-color-bg text-color-white login" @tap="login">登录</button>
  28. <view class="wechat p-fixed left0 right0" style="bottom: 60rpx;">
  29. <button @click="quickLogin" class="d-flex j-center a-center">
  30. <image src="/static/images/weixin.png" mode=""></image>
  31. </button>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import { encryptPassword } from '@/utils/password';
  37. export default {
  38. data() {
  39. return {
  40. userName: '', // 用户名
  41. passWord: '', // 密码
  42. rememberPsw: true // 记住密码
  43. };
  44. },
  45. // 页面初始加载
  46. mounted() {
  47. const that = this;
  48. // 缓存的账号
  49. const cache_userName = uni.getStorageSync('cache_userName');
  50. // 缓存的密码
  51. const cache_passWord = uni.getStorageSync('cache_passWord');
  52. // 有缓存就赋值给文本没有就清空
  53. if (cache_userName && cache_passWord) {
  54. that.userName = cache_userName;
  55. that.passWord = cache_passWord;
  56. } else {
  57. that.userName = '';
  58. that.passWord = '';
  59. }
  60. },
  61. onShow() {
  62. if (this.$BaseTool.Util.isDev()) {
  63. this.userName = 'superadmin'
  64. this.passWord = '123456'
  65. }
  66. },
  67. methods: {
  68. // 找回密码
  69. forgetPass() {
  70. },
  71. // 复选框
  72. checkboxChange: function (e) {
  73. if (e.detail.value.length == 1) {
  74. // 获取缓存的账号
  75. uni.getStorageSync('cache_userName', this.userName);
  76. uni.getStorageSync('cache_passWord', this.passWord);
  77. } else {
  78. uni.removeStorageSync('cache_userName');
  79. uni.removeStorageSync('cache_passWord');
  80. }
  81. },
  82. // 登录
  83. login() {
  84. if (!this.userName) {
  85. return this.$refs.uToast.show({
  86. title: '请输入用户名',
  87. type: 'default',
  88. icon: false
  89. });
  90. } else if (!this.passWord) {
  91. return this.$refs.uToast.show({
  92. title: '请输入密码',
  93. type: 'default',
  94. icon: false
  95. });
  96. }
  97. this.$Http
  98. .mobileLogin({
  99. username: this.userName,
  100. password: encryptPassword(this.passWord),
  101. grant_type: 'password',
  102. scope: 'server'
  103. })
  104. .then(res => {
  105. // 缓存账号和密码
  106. if (this.rememberPsw) {
  107. uni.setStorageSync('cache_userName', this.userName);
  108. uni.setStorageSync('cache_passWord', this.passWord);
  109. } else {
  110. uni.removeStorageSync('cache_userName');
  111. uni.removeStorageSync('cache_passWord');
  112. }
  113. // 如果openId有,则绑定openId
  114. const openId = uni.getStorageSync('openId', this.userName);
  115. if (openId != null && openId !== '') {
  116. this.$Http
  117. .bindUserAndOpenId(openId)
  118. .then(res => {
  119. uni.removeStorageSync('openId');
  120. });
  121. }
  122. });
  123. },
  124. // 微信快捷登录
  125. quickLogin() {
  126. this.$Http.loginQuickly().then(res => {
  127. const url = res.data
  128. if (url !== '' && url !== null && url != undefined) {
  129. // 请求用户授权
  130. window.location.href = url
  131. }
  132. })
  133. }
  134. }
  135. };
  136. </script>
  137. <style lang="scss" scoped>
  138. .top {
  139. font-size: unit(28, rpx);
  140. padding-top: unit(90, rpx);
  141. image {
  142. width: unit(170, rpx);
  143. height: unit(123, rpx);
  144. }
  145. }
  146. .name {
  147. font-size: unit(42, rpx);
  148. color: #333333;
  149. margin: unit(80, rpx) 0 unit(80, rpx);
  150. }
  151. .input {
  152. width: unit(600, rpx);
  153. margin: 0 auto;
  154. input {
  155. border-bottom: unit(1, rpx) solid #e6e6e6;
  156. height: unit(100, rpx);
  157. line-height: unit(100, rpx);
  158. }
  159. }
  160. .login {
  161. width: unit(600, rpx);
  162. height: unit(100, rpx);
  163. margin: unit(100, rpx) auto 0;
  164. border-radius: unit(80, rpx);
  165. }
  166. .tip {
  167. width: unit(600, rpx);
  168. margin: unit(30, rpx) auto;
  169. text-align: right;
  170. font-size: unit(26, rpx);
  171. font-weight: 500;
  172. }
  173. .wechat {
  174. margin-top: unit(90, rpx);
  175. button {
  176. background-color: #FFFFFF;
  177. &::after {
  178. border: none;
  179. }
  180. image {
  181. width: unit(90, rpx);
  182. height: unit(90, rpx);
  183. }
  184. }
  185. }
  186. .mui-checkbox input[type='checkbox']:checked:before {
  187. color: #00bbb1;
  188. }
  189. .RememberPass {
  190. color: #adadad;
  191. margin-top: 5px;
  192. }
  193. .RememberCheck {
  194. margin-left: 30px;
  195. color: #adadad;
  196. }
  197. </style>