index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view>
  3. <view class="loginway">
  4. <div class="navigation"></div>
  5. <image class="loginimg" mode="widthFix" src="/static/login/logo_word.png"></image>
  6. <view class="input_wrap">
  7. <up-form labelPosition="left" :model="form" :rules="rules" ref="loginFormRef">
  8. <up-form-item label="" prop="username" class="inputFormWrap">
  9. <up-input shape="circle" clearable prefixIcon="/static/login/icon-account.png"
  10. :prefixIconStyle="prefixIconStyle" v-model="form.username" placeholder="请输入账号"></up-input>
  11. </up-form-item>
  12. <up-form-item label="" prop="password" class="inputFormWrap">
  13. <up-input shape="circle" clearable password prefixIcon="/static/login/icon-password.png"
  14. :prefixIconStyle="prefixIconStyle" v-model="form.password" placeholder="请输入密码"></up-input>
  15. </up-form-item>
  16. <up-form-item label="" prop="" class="inputFormWrap">
  17. <up-checkbox-group v-model="checkboxs" placement="column" @change="changeRemember">
  18. <up-checkbox :label="'记住密码'" :name="'remember'"></up-checkbox>
  19. </up-checkbox-group>
  20. </up-form-item>
  21. <up-form-item label="" prop="agreePrivacy" class="inputFormWrap agree_form_item">
  22. <view class="agree_row">
  23. <up-checkbox-group v-model="agreePrivacyList" placement="row" @change="onAgreeChange">
  24. <up-checkbox :name="'agree'"></up-checkbox>
  25. </up-checkbox-group>
  26. <text class="agree_text">我已阅读并同意</text>
  27. <text class="agree_link" @click="toPrivacy">《隐私政策》</text>
  28. </view>
  29. </up-form-item>
  30. <up-form-item>
  31. <up-button type="primary" text="登录" shape="circle" :loading="loading" @click="handleLogin"></up-button>
  32. </up-form-item>
  33. </up-form>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script setup lang="ts">
  39. import { ref, onMounted } from 'vue'
  40. import { loginApi } from '@/apis/login'
  41. import type { Login_Params, userInfo_Result } from '@/types/login'
  42. import { computed } from 'vue'
  43. const remember = computed(() => {
  44. return checkboxs.value.length > 0
  45. })
  46. const prefixIconStyle = {
  47. width: "16px",
  48. height: "16px",
  49. marginRight: "4px",
  50. marginLeft: "10px"
  51. }
  52. const rules = ref({
  53. username: {
  54. type: 'string',
  55. required: true,
  56. message: '请输入账号',
  57. trigger: []
  58. },
  59. password: {
  60. type: 'string',
  61. required: true,
  62. message: '请输入密码',
  63. trigger: []
  64. },
  65. agreePrivacy: {
  66. required: true,
  67. message: '请阅读并同意《隐私政策》',
  68. trigger: [],
  69. validator: (rule: any, value: any, callback: any) => {
  70. if(!value){
  71. callback(new Error('请阅读并同意《隐私政策》'));
  72. }else{
  73. callback();
  74. }
  75. }
  76. }
  77. })
  78. const form = ref<Login_Params>({
  79. username: '',
  80. password: '',
  81. systemCode: "system_crm",
  82. clientFlag: "2",
  83. code: "996007qa.code",
  84. uuid: "123",
  85. agreePrivacy: false
  86. })
  87. const checkboxs = ref<string[]>([])
  88. const agreePrivacyList = ref<string[]>([])
  89. const getUserByCache = () => {
  90. const savedUsername = uni.getStorageSync('username');
  91. const savedPassword = uni.getStorageSync('password');
  92. if (savedUsername && savedPassword) {
  93. form.value.username = savedUsername;
  94. form.value.password = savedPassword;
  95. checkboxs.value = ['remember']
  96. }
  97. }
  98. const onAgreeChange = (list: string[]) => {
  99. form.value.agreePrivacy = (list || []).indexOf('agree') >= 0;
  100. }
  101. const toPrivacy = () => {
  102. uni.navigateTo({ url: '/pages/privacy/index' });
  103. }
  104. const changeRemember = (value: string[]) => {
  105. if (value.length > 0) {
  106. uni.setStorageSync('username', form.value.username);
  107. uni.setStorageSync('password', form.value.password);
  108. } else {
  109. uni.removeStorageSync('username');
  110. uni.removeStorageSync('password');
  111. }
  112. }
  113. const loginFormRef = ref<any>(null)
  114. const loading = ref<boolean>(false)
  115. const handleLogin = () => {
  116. loginFormRef.value.validate().then(async () => {
  117. loading.value = true
  118. if (remember.value) {
  119. uni.setStorageSync('username', form.value.username);
  120. uni.setStorageSync('password', form.value.password);
  121. } else {
  122. uni.removeStorageSync('username');
  123. uni.removeStorageSync('password');
  124. }
  125. const res = await loginApi.login(form.value)
  126. uni.setStorageSync('token', res.data.access_token)
  127. const infoRes = await loginApi.getInfo()
  128. uni.setStorageSync('userInfo', infoRes.user)
  129. loading.value = false
  130. uni.showToast({ title: '登录成功', icon: 'success' })
  131. setTimeout(() => {
  132. uni.reLaunch({ url: '/pages/repair/index' })
  133. }, 50)
  134. }).catch((res: any) => {
  135. uni.$u.toast(res[0].message);
  136. })
  137. }
  138. onMounted(() => {
  139. getUserByCache();
  140. })
  141. </script>
  142. <style lang="scss" scoped>
  143. .inputFormWrap {
  144. :deep(.u-border) {
  145. border: 1px solid #dadbde !important;
  146. }
  147. }
  148. .agree_form_item {
  149. :deep(.u-form-item__body__right) {
  150. flex: 1;
  151. }
  152. }
  153. .agree_row {
  154. display: flex;
  155. align-items: center;
  156. flex-wrap: wrap;
  157. }
  158. .agree_text {
  159. font-size: 26rpx;
  160. color: #606266;
  161. margin-left: 8rpx;
  162. }
  163. .agree_link {
  164. font-size: 26rpx;
  165. color: #108cff;
  166. margin-left: 4rpx;
  167. }
  168. page {
  169. background: #fff;
  170. }
  171. .loginway {
  172. display: flex;
  173. flex-direction: column;
  174. height: 100vh;
  175. .navigation {
  176. background-color: #108cff;
  177. width: 100%;
  178. height: 120rpx;
  179. }
  180. .loginimg {
  181. display: block;
  182. width: 100%;
  183. height: 100%;
  184. }
  185. .input_wrap {
  186. padding: 20rpx 30rpx;
  187. }
  188. }
  189. </style>