login.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. uni.$emit('login',{userId:res.userId})
  69. const tokens = uni.getStorageSync('token')
  70. const userId = uni.getStorageSync('userId')
  71. const params = {
  72. token: res.token,
  73. data: {
  74. pharmacistUserId: res.userId,
  75. onlineStatus: 0
  76. }
  77. }
  78. const {data:res} = await updateOnlineStatus(params)
  79. uni.redirectTo({
  80. url:"/pages/index/index"
  81. })
  82. } else {
  83. uni.redirectTo({
  84. url:"/pages/index/index"
  85. })
  86. console.log('登录失败')
  87. uni.$showMsg('登录失败', 1500)
  88. }
  89. }
  90. const handleChange = ()=>{
  91. formData.value.remember = !formData.value.remember
  92. // 如果为true本地保存账号密码
  93. console.log('handleChange', formData.value)
  94. }
  95. const changePassword = ()=>{
  96. showPassword.value = ! showPassword.value
  97. }
  98. onMounted(() => {
  99. const name = uni.getStorageSync('username')
  100. const password = uni.getStorageSync('password')
  101. const remember = uni.getStorageSync('remember')
  102. if (name && password && remember) {
  103. formData.value.name = name
  104. formData.value.password = password
  105. formData.value.remember = remember
  106. }
  107. })
  108. </script>
  109. <style lang="scss">
  110. @import "@/static/iconfont.css";
  111. .main{
  112. justify-content: center;
  113. align-items: center;
  114. background-color: #fff;
  115. .login {
  116. display: flex;
  117. flex-direction:column;
  118. align-items: center;
  119. width: 1074px;
  120. border-radius: 40rpx;
  121. background-color: #fff;
  122. margin-top: 100px;
  123. :deep(.uni-forms){
  124. margin-top: 80rpx;
  125. width: 1074px;
  126. };
  127. .logo{
  128. display: flex;
  129. .faceu{
  130. display: flex;
  131. justify-content: center;
  132. align-items: center;
  133. width: 780px;
  134. height: 544px;
  135. }
  136. }
  137. .title {
  138. font-size: 50px;
  139. margin-top: 50px;
  140. width: 1074px;
  141. display: flex;
  142. justify-content: left;
  143. flex-direction:row;
  144. .text{
  145. }
  146. }
  147. :deep(.uni-forms-item__content) {
  148. display: flex;
  149. flex-direction:row;
  150. border-bottom: 1px solid #bcbcbc;
  151. .input{
  152. margin-left: 20rpx;
  153. width: 1000px;
  154. height: 48px;
  155. color:#bcbcbc;
  156. display: flex;
  157. align-items: center;
  158. justify-content: space-between;
  159. :deep(.uni-input-wrapper){
  160. font-size: 48px;
  161. width: 1000px;
  162. }
  163. }
  164. .item{
  165. font-size: 28px;
  166. color: #bcbcbc;
  167. }
  168. }
  169. :deep(.uni-label-pointer) {
  170. margin-left: 10rpx;
  171. }
  172. .button {
  173. background-color: #fff;
  174. margin-top: 40rpx;
  175. color: #fff;
  176. height: 30rpx;
  177. width: 400rpx;
  178. }
  179. }
  180. }
  181. </style>