index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="pagecontent overflow" v-loading="loading"
  3. style="background-image: linear-gradient(to bottom right, rgb(240, 248, 253), rgb(225, 241, 252));">
  4. <div class="content">
  5. <div class="p-3 text-center ">
  6. <div class="mt-4">
  7. <img :src="logo" alt="" width="50" height="50">
  8. </div>
  9. <div class="text-center font-bold text-dark mt-4">
  10. 医生登录
  11. </div>
  12. <div class="text-center font-bold text-dark mt-3 text-center">
  13. <el-form size="mini" ref="form" :model="formInline" class="px-3 " :rules="rules">
  14. <el-form-item prop="username">
  15. <el-input prefix-icon="el-icon-user" v-model="formInline.username" placeholder="请输入账号" />
  16. </el-form-item>
  17. <el-form-item prop="password">
  18. <el-input type="password" prefix-icon="el-icon-lock" v-model="formInline.password" placeholder="请输入密码" />
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" @click="handleLogin" class="text-center mx-auto w-100">登录</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </div>
  25. <div class="fs-10 text-gry mt-5">
  26. <Footer />
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. import Footer from '../../components/footer/index.vue'
  34. import { isPassword } from '@/utils/validate.js'
  35. import logo from '@/assets/logo.png'
  36. import { mapActions } from 'vuex'
  37. import { ipcRenderer } from 'electron'
  38. export default {
  39. name: "Login",
  40. components: {
  41. Footer
  42. },
  43. data() {
  44. const validateUsername = (rule, value, callback) => {
  45. if ('' === value) callback(new Error('手机号不能为空'))
  46. else callback()
  47. }
  48. const validatePassword = (rule, value, callback) => {
  49. if (!isPassword(value)) callback(new Error('密码不能少于6位'))
  50. else callback()
  51. }
  52. let formInline = process.env.NODE_ENV == "development" ? {
  53. username: '18812312312', password: '123456' //'cxsrmyyyljkjtfhfy@202098'
  54. } : {
  55. username: localStorage.getItem('useraccount') || '',
  56. password: localStorage.getItem('password') || '',
  57. }
  58. return {
  59. formInline,
  60. logo,
  61. rules: {
  62. username: [
  63. {
  64. required: true,
  65. trigger: 'blur',
  66. validator: validateUsername,
  67. },
  68. ],
  69. password: [
  70. {
  71. required: true,
  72. trigger: 'blur',
  73. validator: validatePassword,
  74. },
  75. ],
  76. }, loading: false
  77. }
  78. },
  79. computed: {
  80. },
  81. created() {
  82. },
  83. methods: {
  84. onSubmit() {
  85. // this.$router.push('/userlist')
  86. // this.$api.login()
  87. },
  88. ...mapActions({
  89. logout: 'user/logout',
  90. login: 'user/login',
  91. getUserInfo: 'user/getUserInfo',
  92. getHospitalInfo: 'user/getHospitalInfo',
  93. findVisitSum: 'patient/findVisitSum'
  94. }),
  95. handleRoute() {
  96. return this.redirect === '/404' || this.redirect === '/403'
  97. ? '/'
  98. : '/home' //this.redirect
  99. },
  100. handleLogin() {
  101. let t = this
  102. t.loading = true
  103. t.$refs.form.validate(async (valid) => {
  104. if (valid)
  105. try {
  106. await t.login(t.formInline).then(() => {
  107. localStorage.setItem('username', t.formInline.username)
  108. localStorage.setItem('password', t.formInline.password)
  109. localStorage.setItem('useraccount', t.formInline.username)
  110. // ipcRenderer.send('setTray', { type: 'login' })
  111. try {
  112. Promise.all([
  113. t.getUserInfo(),
  114. t.$api.getHospitalInfo(),
  115. t.findVisitSum()
  116. ]).then((resall) => {
  117. let timer = setInterval(() => {
  118. t.findVisitSum().then((res)=>{
  119. if(res.code==401){
  120. clearInterval(timer)
  121. t.logout().then(() => {
  122. t.$router.push('/home/login')
  123. ipcRenderer.send('removeTray')
  124. }).catch((e) => {
  125. console.log(e)
  126. })
  127. }
  128. })
  129. }, process.env.NODE_ENV == "development"?1000 * 10:1000 * 60)
  130. t.$router.push('patientlist')
  131. ipcRenderer.send('setTray', { type: 'user', data: resall[0] });
  132. })
  133. } finally {
  134. t.loading = false
  135. }
  136. }).catch((e) => {
  137. console.log(127,e)
  138. })
  139. } finally {
  140. this.loading = false
  141. }
  142. })
  143. },
  144. },
  145. }
  146. </script>
  147. <style lang="less" scoped>
  148. .content {
  149. margin: 5px;
  150. height: calc(100vh -8px);
  151. border-radius: 5px;
  152. }
  153. </style>