index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <div class="cy-person">
  3. <el-dropdown>
  4. <div class="menu-userinfo">
  5. <el-avatar shape="square" size="small" @error="errorHandler">
  6. <img :src="avatarDefault"/>
  7. </el-avatar>
  8. <span>{{ name }}</span>
  9. </div>
  10. <el-dropdown-menu slot="dropdown">
  11. <!-- <el-dropdown-item>详细信息</el-dropdown-item>-->
  12. <el-dropdown-item @click.native="reloadPage">首页</el-dropdown-item>
  13. <el-dropdown-item v-if="roleCodeList.indexOf(__self.clientRole) > -1" @click.native="getWarnInfo">报警信息</el-dropdown-item>
  14. <el-dropdown-item @click.native="updateUserPwd">修改密码</el-dropdown-item>
  15. <el-dropdown-item @click.native="checkApplicationUpdate">关于我们</el-dropdown-item>
  16. <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
  17. </el-dropdown-menu>
  18. </el-dropdown>
  19. <!-- 用户密码修改 -->
  20. <el-dialog
  21. title="修改密码"
  22. width="500px"
  23. center
  24. v-dialog-drag
  25. v-if="dialogPwdVisible"
  26. :before-close="dialogClose"
  27. :visible.sync="dialogPwdVisible"
  28. :close-on-click-modal="false"
  29. :append-to-body="true">
  30. <div>
  31. <el-form ref="userPwdForm" :model='userPwdForm' :rules="userPwdRules" label-width='100px'>
  32. <el-form-item label='原密码' prop="password">
  33. <el-input v-model.trim='userPwdForm.password'
  34. type="password"
  35. auto-complete="off"
  36. placeholder="请输入原密码"></el-input>
  37. </el-form-item>
  38. <el-form-item label='新密码' prop="newPassword">
  39. <el-input v-model.trim='userPwdForm.newPassword'
  40. type="password"
  41. auto-complete="off"
  42. placeholder="请输入新密码"></el-input>
  43. </el-form-item>
  44. <el-form-item label='确认密码' prop="confirmPassword">
  45. <el-input v-model.trim='userPwdForm.confirmPassword'
  46. type="password"
  47. auto-complete="off"
  48. placeholder="请再次输入新密码"></el-input>
  49. </el-form-item>
  50. </el-form>
  51. </div>
  52. <div style="text-align: center; margin-top: 40px;">
  53. <el-button type="primary" @click="updateUserPwdEvent">确定</el-button>
  54. <el-button @click="dialogClose">取消</el-button>
  55. </div>
  56. </el-dialog>
  57. <!-- 关于我们 -->
  58. <el-dialog
  59. title=""
  60. width="300px"
  61. center
  62. v-dialog-drag
  63. v-if="dialogAboutVisible"
  64. :before-close="dialogClose"
  65. :visible.sync="dialogAboutVisible"
  66. :close-on-click-modal="true"
  67. :append-to-body="true">
  68. <div style="text-align: center;">
  69. <div>
  70. <el-image :src="require('@/assets/images/logo.png')" fit="contain" class="c-logo"></el-image>
  71. </div>
  72. <div>
  73. <span style="font-size: 18px; font-weight: bold; font-family: '微软雅黑';">重庆川仪控制系统有限公司</span>
  74. </div>
  75. <div style="margin-top: 50px;">当前版本:{{ appVersion }}</div>
  76. </div>
  77. </el-dialog>
  78. <!-- 报警信息 -->
  79. <el-dialog
  80. title="报警信息"
  81. width="80vw"
  82. class="cy-warn-dialog"
  83. center
  84. v-dialog-drag
  85. v-if="dialogNoticeVisible"
  86. :before-close="dialogClose"
  87. :visible.sync="dialogNoticeVisible"
  88. :close-on-click-modal="true"
  89. :append-to-body="true">
  90. <el-table
  91. :data="tableNoticeData" border :stripe="true"
  92. @sort-change="sortChange"
  93. :header-cell-style="{background: '#E8E8E8'}"
  94. style="width: 100%; height: calc(100% - 50px); overflow: auto;">
  95. <el-table-column label="序号" align="center" width="80">
  96. <template slot-scope="scope">
  97. {{ scope.$index + 1 }}
  98. </template>
  99. </el-table-column>
  100. <el-table-column align="center" sortable="custom" label="标题" prop="noticeTitle" width="350">
  101. </el-table-column>
  102. <el-table-column align="center" label="报警内容" prop="noticeContent">
  103. </el-table-column>
  104. <el-table-column align="center" sortable label="报警时间" prop="createTime" width="200">
  105. </el-table-column>
  106. </el-table>
  107. <el-pagination
  108. style="margin-top: 20px;"
  109. background
  110. layout="prev, pager, next, total"
  111. :current-page="tablePage"
  112. @size-change="sizeChangeEvent"
  113. @current-change="currentChangeEvent"
  114. :total="tableTotal">
  115. </el-pagination>
  116. </el-dialog>
  117. </div>
  118. </template>
  119. <script>
  120. import avatarDefault from '@/assets/images/default.png'
  121. import {mapGetters} from 'vuex'
  122. import {updatePwd} from '@/api/user'
  123. import {getPubKey} from '@/utils/auth'
  124. import {encrypt} from '@/utils/jsencrypt'
  125. import {customCompare, showAlertWin, showLoading} from '@/utils/cqcy'
  126. import {getAllMessageNotice} from "@/api/basic";
  127. let pkg = require('../../../package.json')
  128. export default {
  129. name: "HeaderPersonal",
  130. data() {
  131. let checkPwd = ((rule, value, callback) => {
  132. if (value.trim().length == 0) {
  133. callback(new Error("请输入确认密码"))
  134. } else if (value != this.userPwdForm.newPassword) {
  135. callback(new Error("两次密码不一致"))
  136. } else {
  137. callback()
  138. }
  139. })
  140. return {
  141. roleCodeList: [],
  142. avatarDefault: avatarDefault,
  143. dialogPwdVisible: false,
  144. dialogAboutVisible: false,
  145. dialogNoticeVisible: false,
  146. appVersion: '',
  147. tableNoticeData: [],
  148. tablePage: 1,
  149. tableLimit: 10,
  150. tableTotal: 0,
  151. userPwdForm: {
  152. password: '',
  153. newPassword: '',
  154. confirmPassword: ''
  155. },
  156. userPwdRules: {
  157. password: [
  158. {required: true, message: '原密码不能为空', trigger: 'blur'},
  159. {min: 6, max: 20, message: '原密码长度必须介于 6 和 20 之间', trigger: 'blur'}
  160. ],
  161. newPassword: [
  162. {required: true, message: '新密码不能为空', trigger: 'blur'},
  163. {min: 6, max: 20, message: '新密码长度必须介于 6 和 20 之间', trigger: 'blur'},
  164. {
  165. pattern: /(?!^\d+$)(?!^[A-Za-z]+$)(?!^[^A-Za-z0-9]+$)(?!^.*[\u4E00-\u9FA5].*$)^\S{6,20}$/,
  166. message: '密码必须由数字、字母或字符任意两种组合',
  167. trigger: 'blur'
  168. },
  169. ],
  170. confirmPassword: [
  171. {required: true, message: '确认密码不能为空', trigger: 'blur'},
  172. {min: 6, max: 20, message: '新密码长度必须介于 6 和 20 之间', trigger: 'blur'},
  173. {validator: checkPwd, required: true, trigger: 'blur'}
  174. ]
  175. }
  176. }
  177. },
  178. inject: ['__self'],
  179. computed: {
  180. ...mapGetters([
  181. 'sidebar',
  182. 'avatar',
  183. 'name',
  184. 'uid',
  185. 'device',
  186. 'roles'
  187. ])
  188. },
  189. mounted() {
  190. this.roleCodeList = []
  191. this.roles.forEach((role) => {
  192. this.roleCodeList.push(role.roleCode)
  193. })
  194. },
  195. methods: {
  196. sortChange({ prop, order }) {
  197. this.tableNoticeData.sort(customCompare(prop, order))
  198. },
  199. errorHandler() {
  200. return true
  201. },
  202. /**
  203. * 修改密码
  204. */
  205. updateUserPwd() {
  206. if (this.$refs['userPwdForm'])
  207. this.$refs['userPwdForm'].resetFields()
  208. this.dialogPwdVisible = true
  209. },
  210. checkApplicationUpdate() {
  211. this.appVersion = 'V' + pkg.version
  212. this.dialogAboutVisible = true
  213. },
  214. reloadPage() {
  215. this.$router.push({path: '/', query: {}})
  216. // window.location.reload()
  217. this.$router.go(0)
  218. },
  219. updateUserPwdEvent() {
  220. this.$refs['userPwdForm'].validate(valid => {
  221. if (valid) {
  222. const loading = showLoading(this, '修改中,请稍候···')
  223. let pubKey = getPubKey()
  224. let data = {
  225. 'password': encrypt(this.userPwdForm.password, pubKey),
  226. 'newPassword': encrypt(this.userPwdForm.newPassword, pubKey),
  227. 'userName': this.name,
  228. 'userId': this.uid
  229. }
  230. if (this.userPwdForm.password == this.userPwdForm.newPassword) {
  231. loading.close()
  232. this.$message({
  233. message: '修改失败,新密码与原密码不能相同!',
  234. type: 'error'
  235. })
  236. return
  237. }
  238. updatePwd(data).then(res => {
  239. loading.close()
  240. if (res.code != 200) {
  241. this.$message({
  242. message: res.msg,
  243. type: 'error'
  244. })
  245. return
  246. }
  247. this.$message({
  248. message: '密码修改成功!',
  249. type: 'success'
  250. })
  251. this.$store.dispatch('user/Logout').then(() => {
  252. // location.href = '/index';
  253. this.$router.push({path: '/', query: {}})
  254. window.location.reload()
  255. }).catch(() => {
  256. })
  257. this.dialogClose()
  258. }).catch((e) => {
  259. loading.close()
  260. showAlertWin(this, e)
  261. })
  262. }
  263. })
  264. },
  265. /** 数据条数改变 */
  266. sizeChangeEvent(val) {
  267. this.tablePage = 1
  268. this.tableLimit = val
  269. this.getWarnInfo()
  270. },
  271. /** 页码改变 */
  272. currentChangeEvent(val) {
  273. this.tablePage = val
  274. this.getWarnInfo()
  275. },
  276. /** 获取报警信息 */
  277. getWarnInfo() {
  278. const loading = showLoading(this, '加载中,请稍候···')
  279. let params = {
  280. 'page': this.tablePage,
  281. 'limit': this.tableLimit,
  282. }
  283. getAllMessageNotice(params).then(res => {
  284. loading.close()
  285. if (!res || !res.data) {
  286. return
  287. }
  288. this.dialogNoticeVisible = true
  289. this.tableTotal = res.data.count
  290. this.tableNoticeData = res.data.messageNoticeList
  291. }).catch((e) => {
  292. loading.close()
  293. showAlertWin(this, e)
  294. })
  295. },
  296. /**
  297. * 退出登录
  298. */
  299. logout() {
  300. this.$confirm('您确定要退出系统吗?', '提示', {
  301. confirmButtonText: '确定',
  302. cancelButtonText: '取消',
  303. customClass: 'close_confirm',
  304. closeOnClickModal: false,
  305. type: 'warning'
  306. }).then(() => {
  307. this.$store.dispatch('user/Logout').then(() => {
  308. // location.href = '/index';
  309. this.$router.push({path: '/', query: {}})
  310. window.location.reload()
  311. }).catch(() => {
  312. })
  313. }).catch(() => {
  314. });
  315. },
  316. /** 弹出层关闭事件 */
  317. dialogClose(done) {
  318. if (this.$refs['userPwdForm'])
  319. this.$refs['userPwdForm'].resetFields()
  320. if (typeof (done) === 'function') {
  321. done()
  322. } else {
  323. this.dialogPwdVisible = false
  324. this.dialogAboutVisible = false
  325. }
  326. }
  327. }
  328. }
  329. </script>
  330. <style rel="stylesheet/scss" lang="scss">
  331. .cy-person {
  332. background-color: #2c3e50;
  333. height: 70px;
  334. width: 100%;
  335. padding-right: 20px;
  336. display: flex;
  337. flex-direction: row;
  338. flex-wrap: nowrap;
  339. align-content: center;
  340. justify-content: flex-end;
  341. align-items: center;
  342. }
  343. .menu-userinfo {
  344. color: white;
  345. cursor: pointer;
  346. display: flex;
  347. align-items: center;
  348. i {
  349. color: white;
  350. }
  351. }
  352. .el-avatar {
  353. margin-right: 5px;
  354. }
  355. .cy-warn-dialog {
  356. .el-dialog {
  357. height: 70vh;
  358. .el-dialog__body {
  359. height: calc(100% - 60px);
  360. }
  361. }
  362. }
  363. </style>