login.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="main">
  3. <view class="login">
  4. <view class="logo">
  5. <image class="faceu" aspectFill src="/static/login@2x.png" />
  6. </view>
  7. <view class="title">
  8. <text class="text">中药处方煎配溯源管理</text>
  9. </view>
  10. <uni-forms :model="formData">
  11. <uni-forms-item name="name">
  12. <uni-icons class="item" type="person-filled" color="#cfcfcf" size="50"></uni-icons>
  13. <view class="input">
  14. <input type="text" class="item" v-model="formData.name" placeholder="请输入账号" />
  15. </view>
  16. </uni-forms-item>
  17. <uni-forms-item name="password">
  18. <uni-icons type="locked" class="item" color="#cfcfcf" size="50"></uni-icons>
  19. <view class="input">
  20. <input class="item" v-model="formData.password" :password="showPassword" placeholder="请输入密码" />
  21. <!-- <text class="uni-icon" :class="[!showPassword ? 'uni-eye-active' : '']" @click="changePassword">&#xe568;</text> -->
  22. <uni-icons custom-prefix="iconfont" class="item" :type="showPassword?'icon-biyanjing':'icon-yanjing'" color="#cfcfcf" size="50" @click="changePassword"></uni-icons>
  23. <!-- :type="showPassword?'icon-biyanjing':'icon-yanjing'" -->
  24. </view>
  25. </uni-forms-item>
  26. <label for="" class="radio">
  27. <switch :checked="formData.remember" @change="handleChange" /> 记住密码
  28. </label>
  29. </uni-forms>
  30. <button class="button" @click="submit">登录</button>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. name: ''
  37. }
  38. </script>
  39. <script setup>
  40. import { onMounted, ref } from 'vue'
  41. import { login } from '@/static/request.js'
  42. const showPassword = ref(false)
  43. const formData = ref({
  44. name:'',
  45. password:'',
  46. remember:false
  47. })
  48. const submit = async ()=> {
  49. console.log('formData', formData.value)
  50. if(formData.value.name && formData.value.password && formData.value.remember=== true ){
  51. uni.setStorageSync('username', formData.value.name);
  52. uni.setStorageSync('password', formData.value.password);
  53. uni.setStorageSync('remember', formData.value.remember);
  54. }
  55. const params = {
  56. username: formData.value.name,
  57. password: formData.value.password,
  58. code: '2',
  59. }
  60. // uni.setStorageSync('token', 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjQ0ZTExZWNlLTdlNGUtNGZjNi1iMTgzLTZhMTM2NTJiZTVlZiJ9.uZpHzo-AnKFcG3qwdTz85Wd61r1BUSS4TENUgsy1aQHZgdP1gnOZA1XUdFJChO1ReCzvyUENcMgG6GNrh1m_IQ')
  61. // uni.redirectTo({
  62. // url:"/pages/index/index"
  63. // })
  64. const res = await login(params)
  65. if (res.code === 200 && res.token) {
  66. uni.setStorageSync('token', res.token)
  67. uni.setStorageSync('userId', res.userId)
  68. const tokens = uni.getStorageSync('token')
  69. const userId = uni.getStorageSync('userId')
  70. const params = {
  71. token: res.token,
  72. data: {
  73. pharmacistUserId: res.userId,
  74. onlineStatus: 0
  75. }
  76. }
  77. const {data:res} = await updateOnlineStatus(params)
  78. uni.redirectTo({
  79. url:"/pages/index/index"
  80. })
  81. } else {
  82. uni.redirectTo({
  83. url:"/pages/index/index"
  84. })
  85. console.log('登录失败')
  86. uni.$showMsg('登录失败', 1500)
  87. }
  88. }
  89. const handleChange = ()=>{
  90. formData.value.remember = !formData.value.remember
  91. // 如果为true本地保存账号密码
  92. console.log('handleChange', formData.value)
  93. }
  94. const changePassword = ()=>{
  95. showPassword.value = ! showPassword.value
  96. }
  97. onMounted(() => {
  98. const name = uni.getStorageSync('username')
  99. const password = uni.getStorageSync('password')
  100. const remember = uni.getStorageSync('remember')
  101. if (name && password && remember) {
  102. formData.value.name = name
  103. formData.value.password = password
  104. formData.value.remember = remember
  105. }
  106. })
  107. </script>
  108. <style lang="scss">
  109. @import "@/static/iconfont.css";
  110. .main{
  111. justify-content: center;
  112. align-items: center;
  113. background-color: #fff;
  114. .login {
  115. display: flex;
  116. flex-direction:column;
  117. align-items: center;
  118. width: 1074px;
  119. border-radius: 40rpx;
  120. background-color: #fff;
  121. margin-top: 100px;
  122. :deep(.uni-forms){
  123. margin-top: 80rpx;
  124. width: 1074px;
  125. };
  126. .logo{
  127. display: flex;
  128. .faceu{
  129. display: flex;
  130. justify-content: center;
  131. align-items: center;
  132. width: 780px;
  133. height: 544px;
  134. }
  135. }
  136. .title {
  137. font-size: 50px;
  138. margin-top: 50px;
  139. width: 1074px;
  140. display: flex;
  141. justify-content: left;
  142. flex-direction:row;
  143. .text{
  144. }
  145. }
  146. :deep(.uni-forms-item__content) {
  147. display: flex;
  148. flex-direction:row;
  149. border-bottom: 1px solid #bcbcbc;
  150. .input{
  151. margin-left: 20rpx;
  152. width: 1000px;
  153. height: 48px;
  154. color:#bcbcbc;
  155. display: flex;
  156. align-items: center;
  157. justify-content: space-between;
  158. :deep(.uni-input-wrapper){
  159. font-size: 48px;
  160. width: 1000px;
  161. }
  162. }
  163. .item{
  164. font-size: 28px;
  165. color: #bcbcbc;
  166. }
  167. }
  168. :deep(.uni-label-pointer) {
  169. margin-left: 10rpx;
  170. }
  171. .button {
  172. background-color: #fff;
  173. margin-top: 40rpx;
  174. color: #fff;
  175. height: 30rpx;
  176. width: 400rpx;
  177. }
  178. }
  179. }
  180. </style>