Login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <!--登录界面-->
  2. <template>
  3. <div class="login" ref="login"
  4. :style="{backgroundColor: `#${loginJson[0] ? loginJson[0].BrackgroupStr.slice(3) : ''}`}">
  5. <section class="login-content" :style="{
  6. width: loginJson[0] ? loginJson[0].Width + 'px' : '',
  7. height: loginJson[0] ? loginJson[0].Height + 'px' : '',
  8. left:loginJson[0] ? loginJson[0].Left + 'px' : '',
  9. top:loginJson[0] ? loginJson[0].Top + 'px' : '',
  10. zIndex: loginJson[0] ? loginJson[0].ZIndex : '',
  11. border: `1px solid #${loginJson[0] ? loginJson[0].BorderStr.slice(3) : ''}`,
  12. backgroundColor: `#${loginJson[0] ? loginJson[0].ForegroundStr.slice(3) : ''}`}"
  13. >
  14. <h2>用户登录</h2>
  15. <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="55px" class="login-form">
  16. <el-form-item label="账号" prop="username">
  17. <el-input v-model="ruleForm.username" prefix-icon="el-icon-user" autofocus @keyup.enter.native="submitForm('ruleForm')"></el-input>
  18. </el-form-item>
  19. <el-form-item label="密码" prop="password">
  20. <el-input type="password" v-model="ruleForm.password" autocomplete="off"
  21. prefix-icon="el-icon-lock" @keyup.20.native="testCapsLock" @keyup.enter.native="submitForm('ruleForm')" show-password></el-input>
  22. </el-form-item>
  23. <el-checkbox v-model="checked" :checked="checked" class="checkedBox">记住用户名和密码</el-checkbox>
  24. <el-form-item>
  25. <el-button type="primary"
  26. :style="{backgroundColor: `#${loginJson[0] ? loginJson[0].BTNForegroundStr.slice(3) : ''}`}"
  27. @click="submitForm('ruleForm')">提交
  28. </el-button>
  29. <el-button type="primary"
  30. :style="{backgroundColor: `#${loginJson[0] ? loginJson[0].BTNForegroundStr.slice(3) : ''}`}"
  31. @click="resetForm('ruleForm')">重置
  32. </el-button>
  33. </el-form-item>
  34. </el-form>
  35. </section>
  36. <!--最小化和关闭按钮-->
  37. <div class="mini" @click="miniWindow">-</div>
  38. <div class="close" @click="closeWindow">×</div>
  39. </div>
  40. </template>
  41. <script>
  42. import {
  43. reqBigScreen,
  44. reqConfigBigScreen,
  45. reqConfigDevice,
  46. reqDevice,
  47. reqLogin,
  48. reqLogout,
  49. reqPreviewSourceList
  50. } from "../api"
  51. import {getStaticFile} from "../../utils/tools"
  52. import storageUtils from "../../utils/storageUtils"
  53. import axios from "axios"
  54. export default {
  55. data() {
  56. const checkUsername = (rule, value, callback) => {
  57. if (!value) {
  58. return callback(new Error('用户名不能为空'))
  59. }
  60. }
  61. const validatePasswrod = (rule, value, callback) => {
  62. if (value === '') {
  63. callback(new Error('请输入密码'))
  64. }
  65. }
  66. return {
  67. ruleForm: {
  68. username: '',
  69. password: '',
  70. },
  71. rules: {
  72. username: [
  73. {validator: checkUsername, trigger: 'blur'}
  74. ],
  75. password: [
  76. {validator: validatePasswrod, trigger: 'blur'}
  77. ]
  78. },
  79. loginJson: [],
  80. staticUrl: this.$store.state.staticUrl,
  81. flag:false, // 大写开启状态
  82. checked:storageUtils.getStatus(), // 记住用户名和密码的状态
  83. user:storageUtils.getUser(), // 本地存储的用户数据
  84. }
  85. },
  86. async beforeCreate() {
  87. this.loginJson = await getStaticFile('EnityLogin.Data')
  88. },
  89. mounted() {
  90. // 如果status为true,对表单进行赋值
  91. if(storageUtils.getStatus() === 'true'){
  92. this.ruleForm.username = this.user.name
  93. this.ruleForm.password = this.user.password
  94. }else {
  95. this.ruleForm.username = ''
  96. this.ruleForm.password = ''
  97. this.checked = false
  98. }
  99. },
  100. updated() {
  101. // 添加背景图片
  102. const backIcon = this.loginJson[0] ? this.loginJson[0].BackIcon : ''
  103. this.$refs.login.style.backgroundImage = backIcon ? 'url(' + `${this.staticUrl}/Data/${backIcon}` + ')' : null
  104. },
  105. methods: {
  106. // 提交表单,登录
  107. async submitForm() {
  108. const {username, password} = this.ruleForm
  109. if (username === '' || password === '') {
  110. this.$message.warning('请输入用户名和密码!')
  111. return
  112. }
  113. const userInfo = {"name": username, "password":password}
  114. // 登录之前先判断本地是否有用户,有的话先退出登录
  115. if(this.user){
  116. // 退出登录
  117. await reqLogout(this.user)
  118. }
  119. // 请求登录
  120. const res = await reqLogin(userInfo, 'login')
  121. if (res.token) {
  122. // 将user保存到vuex的state,同时保存到本地
  123. this.$store.dispatch('saveUser', userInfo)
  124. // 保存记住用户名和密码的状态
  125. storageUtils.saveStatus(this.checked)
  126. // 将token保存到会议存储
  127. storageUtils.saveToken(res.token)
  128. // 跳转到管理界面
  129. this.$router.replace('/admin')
  130. // 上传配置数据和获取接口数据
  131. axios.get('static/Data/EnityBigScreen.Data').then(async res => {
  132. if (res.status === 200) {
  133. const result = await reqConfigBigScreen(res.data)
  134. if(result[0].ID){
  135. console.log('上传大屏配置文件成功!')
  136. }
  137. }
  138. })
  139. axios.get('static/Data/EnityDevice.Data').then(async res => {
  140. if (res.status === 200) {
  141. const result = await reqConfigDevice(res.data)
  142. if(result[0].ID){
  143. console.log('上传设备配置文件成功!')
  144. const windowJson = await getStaticFile('EnityWindow.Data')
  145. const arr = windowJson.filter(item => item.IsVisibility === true)
  146. const homeJson = arr[0]
  147. this.$store.dispatch('updateHomeJson',homeJson)
  148. // 获取大屏,信号源,设备数据,label数据并保存到vuex中
  149. const bigScreenJson = await reqBigScreen()
  150. const signalListJson = await reqPreviewSourceList()
  151. const deviceJson = await reqDevice()
  152. const labelJson = await getStaticFile('EnityLable.Data')
  153. this.$store.dispatch('updateLabelJson',labelJson)
  154. this.$store.dispatch('saveBigscreen',bigScreenJson)
  155. this.$store.dispatch('saveSignalList',signalListJson)
  156. this.$store.dispatch('saveDevice',deviceJson)
  157. }
  158. }
  159. })
  160. } else {
  161. this.$message.error('用户名或密码错误!')
  162. }
  163. },
  164. // 重置表单
  165. resetForm(formName) {
  166. this.$refs[formName].resetFields()
  167. },
  168. // 监视开启和关闭大写
  169. testCapsLock() {
  170. this.flag = !this.flag
  171. if(this.flag){
  172. this.$message({
  173. message: '大写开启',
  174. type: 'success'
  175. })
  176. }else {
  177. this.$message('大写关闭')
  178. }
  179. },
  180. // 最小化窗口
  181. miniWindow() {
  182. require('electron').ipcRenderer.send('window-min')
  183. },
  184. // 关闭窗口
  185. async closeWindow() {
  186. // 需要先退出登录
  187. // await reqLogout(this.user)
  188. require('electron').ipcRenderer.send('window-close')
  189. }
  190. }
  191. }
  192. </script>
  193. <style lang="less">
  194. html, body {
  195. margin: 0;
  196. padding: 0;
  197. .login {
  198. width: 100vw;
  199. height: 100vh;
  200. background-size: 100% 100%;
  201. position: relative;
  202. .login-content {
  203. position: absolute;
  204. h2 {
  205. text-align: center;
  206. font-weight: bold;
  207. margin-bottom: 20px;
  208. }
  209. .el-input {
  210. width: 90%;
  211. }
  212. .login-form {
  213. .login-form-button {
  214. width: 100%;
  215. }
  216. .checkedBox {
  217. margin:0 0 10px 55px;
  218. }
  219. }
  220. }
  221. // 最小化和关闭按钮
  222. .mini {
  223. .miniclose(30px,20px);
  224. &:hover {
  225. background-color: #ccc;
  226. }
  227. }
  228. .close {
  229. .miniclose(0,28px);
  230. &:hover {
  231. background-color: #ccc;
  232. }
  233. }
  234. }
  235. // 带参数的混合
  236. .miniclose(@right,@fontSize) {
  237. position: absolute;
  238. width: 30px;
  239. height: 30px;
  240. top: 0;
  241. right:@right;
  242. text-align: center;
  243. line-height: 30px;
  244. font-size:@fontSize;
  245. cursor:default;
  246. font-weight: 600;
  247. color: #000;
  248. }
  249. }
  250. </style>