user.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. <template>
  2. <!-- :style="{ flex: layoutUserFlexNum }" -->
  3. <div class="layout-navbars-breadcrumb-user pr15">
  4. <!-- <el-dropdown :show-timeout="70" :hide-timeout="50" trigger="click" @command="onComponentSizeChange">
  5. <div class="layout-navbars-breadcrumb-user-icon mr10" title="组件大小">
  6. <i class="iconfont icon-ziti"></i>
  7. </div>
  8. <template #dropdown>
  9. <el-dropdown-menu>
  10. <el-dropdown-item command="large" :disabled="state.disabledSize === 'large'">大型</el-dropdown-item>
  11. <el-dropdown-item command="default" :disabled="state.disabledSize === 'default'">默认</el-dropdown-item>
  12. <el-dropdown-item command="small" :disabled="state.disabledSize === 'small'">小型</el-dropdown-item>
  13. </el-dropdown-menu>
  14. </template>
  15. </el-dropdown>
  16. <div class="layout-navbars-breadcrumb-user-icon mr10" @click="onSearchClick" title="菜单搜索">
  17. <el-icon>
  18. <ele-Search />
  19. </el-icon>
  20. </div>
  21. <div class="layout-navbars-breadcrumb-user-icon mr10" @click="onLayoutSetingClick" title="布局配置">
  22. <i class="icon-skin iconfont"></i>
  23. </div>-->
  24. <div class="layout-navbars-breadcrumb-user-icon mr10" title="消息">
  25. <el-popover placement="bottom" trigger="click" transition="el-zoom-in-top" :width="300" :persistent="false">
  26. <template #reference>
  27. <el-badge :value="messageCount" :max="99" :hidden="messageHidden">
  28. <SvgIcon name="ele-Bell" size="18px"/>
  29. </el-badge>
  30. </template>
  31. <template #default>
  32. <UserNews @onAllReadClick="onAllReadClick"/>
  33. </template>
  34. </el-popover>
  35. </div>
  36. <div class="layout-navbars-breadcrumb-user-icon mr10" @click="onLockScreen" title="锁屏">
  37. <SvgIcon name="ele-Lock" size="18px"/>
  38. </div>
  39. <!-- <div class="layout-navbars-breadcrumb-user-icon mr10" @click="onScreenfullClick" :title="isScreenfull ? '关全屏' : '开全屏'" >
  40. <i class="iconfont" :class="!isScreenfull ? 'icon-quanping1' : 'icon-tuichuquanping'"></i>
  41. </div>-->
  42. <el-dropdown :show-timeout="70" :hide-timeout="50" @command="onHandleCommandClick">
  43. <div class="layout-navbars-breadcrumb-user-link" :title="userInfos.name">
  44. <div class="layout-navbars-breadcrumb-user-link-photoBox">
  45. <el-avatar :src="userInfos.photo" :size="24" class="layout-navbars-breadcrumb-user-link-photo">
  46. <SvgIcon name="ele-UserFilled" color="var(--el-color-primary)" />
  47. </el-avatar>
  48. <span class="text-no-wrap layout-navbars-breadcrumb-user-link-photoBox-name">{{ userInfos.name ? userInfos.name : '' }}</span>
  49. <SvgIcon name="ele-ArrowDown" class="ml3"/>
  50. </div>
  51. </div>
  52. <template #dropdown>
  53. <el-dropdown-menu>
  54. <el-dropdown-item command="/home"> <SvgIcon name="ele-House" /> 首页 </el-dropdown-item>
  55. <el-dropdown-item divided command="setting" v-if="showSetting"> <SvgIcon name="ele-Setting" />系统设置 </el-dropdown-item>
  56. <el-dropdown-item divided command="search"> <SvgIcon name="ele-Search" /> 搜索菜单 </el-dropdown-item>
  57. <el-dropdown-item divided command="changePwd"> <SvgIcon name="ele-Lock" /> 修改密码 </el-dropdown-item>
  58. <el-dropdown-item divided command="logOut"> <SvgIcon name="ele-SwitchButton" />退出 </el-dropdown-item>
  59. </el-dropdown-menu>
  60. </template>
  61. </el-dropdown>
  62. <Search ref="searchRef" />
  63. <!-- 锁频 -->
  64. <el-dialog v-model="dialogVisible" width="400px" draggable title="锁屏">
  65. <el-form :model="state.ruleForm" ref="ruleFormRef" @submit.native.prevent>
  66. <el-form-item label="锁屏密码" prop="pwd" :rules="[{ required: true, message: '请输入锁屏密码', trigger: 'blur' }]">
  67. <el-input show-password placeholder="请输入密码" v-model="state.ruleForm.pwd" @keyup.enter="confirmLock(ruleFormRef)">
  68. <template #prefix>
  69. <el-icon class="el-input__icon">
  70. <ele-Unlock />
  71. </el-icon>
  72. </template>
  73. </el-input>
  74. </el-form-item>
  75. </el-form>
  76. <template #footer>
  77. <span class="dialog-footer">
  78. <el-button @click="dialogVisible = false" class="default-button">取 消</el-button>
  79. <el-button type="primary" @click="confirmLock(ruleFormRef)">确 定</el-button>
  80. </span>
  81. </template>
  82. </el-dialog>
  83. <!-- 修改密码 -->
  84. <el-dialog v-model="showDutyDialog" draggable title="修改密码" width="500px">
  85. <el-form :model="state.dutyForm" label-width="80px" :rules="rules" ref="dutyFormRef">
  86. <el-form-item prop="currentPassword" label="旧密码" class="mb30">
  87. <el-input
  88. class="inputDeep"
  89. clearable
  90. show-password
  91. placeholder="请输旧就密码"
  92. v-model="state.dutyForm.currentPassword"
  93. autocomplete="off"
  94. >
  95. <template #prefix>
  96. <el-icon class="el-input__icon">
  97. <ele-Unlock />
  98. </el-icon>
  99. </template>
  100. </el-input>
  101. </el-form-item>
  102. <el-form-item label="新密码" prop="newPassword" class="mb30">
  103. <el-input
  104. class="inputDeep"
  105. clearable
  106. show-password
  107. placeholder="请输入新密码"
  108. v-model="state.dutyForm.newPassword"
  109. autocomplete="off"
  110. >
  111. <template #prefix>
  112. <el-icon class="el-input__icon">
  113. <ele-Unlock />
  114. </el-icon>
  115. </template>
  116. </el-input>
  117. <div class="intensity">
  118. <span class="psdText">密码强度:{{ modes === 1 ? '弱' : modes === 2 ? '中' : modes === 3 ? '强' : '' }}</span>
  119. <span class="line ruo" :class="modes === 1 ? 'low' : ''"></span>
  120. <span class="line zhong" :class="modes === 2 ? 'middle' : ''"></span>
  121. <span class="line qiang" :class="modes === 3 ? 'high' : ''"></span>
  122. </div>
  123. </el-form-item>
  124. <el-form-item prop="confirmPassword" label="确认密码">
  125. <el-input
  126. class="inputDeep"
  127. clearable
  128. type="password"
  129. show-password
  130. placeholder="请再次输入密码"
  131. v-model="state.dutyForm.confirmPassword"
  132. autocomplete="off"
  133. >
  134. <template #prefix>
  135. <el-icon class="el-input__icon">
  136. <ele-Unlock />
  137. </el-icon>
  138. </template>
  139. </el-input>
  140. </el-form-item>
  141. </el-form>
  142. <template #footer>
  143. <span class="dialog-footer">
  144. <el-button @click="showDutyDialog = false" class="default-button">取 消</el-button>
  145. <el-button type="primary" @click="save(dutyFormRef)" :loading="loading">保 存</el-button>
  146. </span>
  147. </template>
  148. </el-dialog>
  149. </div>
  150. </template>
  151. <script setup lang="ts" name="layoutBreadcrumbUser">
  152. import { defineAsyncComponent, ref, computed, reactive, onMounted } from 'vue';
  153. import { useRouter } from 'vue-router';
  154. import { ElMessageBox, ElMessage, ElNotification, FormInstance } from 'element-plus';
  155. import screenfull from 'screenfull';
  156. import { storeToRefs } from 'pinia';
  157. import { useUserInfo } from '/@/stores/userInfo';
  158. import { useTelStatus } from '/@/stores/telStatus';
  159. import { useThemeConfig } from '/@/stores/themeConfig';
  160. import {Session, Local, Cookie} from '/@/utils/storage';
  161. import mittBus from '/@/utils/mitt';
  162. import { VoiceInterfaceObject } from '/@/utils/PhoneScript';
  163. import { changePwd } from '/@/api/login/user';
  164. // 引入组件
  165. const UserNews = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/userNews.vue'));
  166. const Search = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/search.vue'));
  167. const router = useRouter();
  168. const stores = useUserInfo();
  169. const storesThemeConfig = useThemeConfig();
  170. const { userInfos } = storeToRefs(stores);
  171. const { themeConfig } = storeToRefs(storesThemeConfig);
  172. const usetelStatusStore = useTelStatus();
  173. const { telStatusInfo } = storeToRefs(usetelStatusStore);
  174. const searchRef = ref<RefType>();
  175. const state = reactive({
  176. isScreenfull: false,
  177. disabledI18n: 'zh-cn',
  178. disabledSize: 'large',
  179. dutyForm: {
  180. currentPassword: '',
  181. newPassword: '',
  182. confirmPassword: '',
  183. },
  184. ruleForm: {
  185. pwd: '', // 锁频密码
  186. },
  187. });
  188. const messageCount = ref<number>(2);//消息数量
  189. const messageHidden = computed(() => { //消息是否隐藏
  190. return messageCount.value === 0;
  191. });
  192. // 全部已读点击
  193. const onAllReadClick = () => {
  194. messageCount.value = 0;
  195. };
  196. // 检查密码强度
  197. let modes = ref<number>(0);
  198. const checkPassword = (rule: any, value: string, callback: any) => {
  199. if (!value) {
  200. modes.value = 0;
  201. return callback('新密码不能为空');
  202. }
  203. if (value.length < 8) {
  204. modes.value = 0;
  205. return callback('新密码不少于8位');
  206. }
  207. /*
  208. 最短8位, {6,}
  209. 可以包含小写大母 [a-z] 和大写字母 [A-Z]
  210. 可以包含数字 [0-9]
  211. 可以包含下划线 [ _ ] 和减号 [ - ]
  212. */
  213. if (/^[\w_-]{6,}$/.test(state.dutyForm.newPassword)) {
  214. modes.value = 1;
  215. }
  216. /*
  217. 最短8位, {8,}
  218. 必须包含1个数字
  219. 必须包含1个小写字母
  220. 必须包含1个大写字母
  221. 必须包含1个特殊字符
  222. */
  223. if (/^\S*(?=\S{8,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*.?])\S*$/.test(state.dutyForm.newPassword)) modes.value = 2; //中等
  224. /*
  225. 最短8位, {8,}
  226. 必须包含1个数字
  227. 必须包含1个小写字母
  228. 必须包含1个大写字母
  229. 必须包含2个特殊字符
  230. */
  231. if (/^\S*(?=\S{8,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*.?]{2,})\S*$/.test(state.dutyForm.newPassword)) modes.value = 3; //强密码
  232. if (modes.value == 0 || modes.value == 1) {
  233. return callback('提示:密码不得少于8位数,且必须包含字母大小写和特殊字符'); //弱密码
  234. }
  235. if (value === state.dutyForm.currentPassword) {
  236. return callback('新密码不能与旧密码一致,请重新输入');
  237. }
  238. return callback();
  239. };
  240. // 检查输入密码是否一致
  241. const checkConfirmPassword = (rule: any, value: any, callback: any) => {
  242. if (!value) {
  243. return callback('请再次输入密码');
  244. }
  245. if (value != state.dutyForm.newPassword) {
  246. return callback('两次密码输入不一致,请重新输入');
  247. }
  248. return callback();
  249. };
  250. const rules = reactive({
  251. currentPassword: [{ required: true, message: '请输入旧密码', trigger: ['change', 'blur'] }],
  252. newPassword: [{ required: true, validator: checkPassword, trigger: ['change', 'blur'] }],
  253. confirmPassword: [{ required: true, validator: checkConfirmPassword, trigger: 'blur' }],
  254. });
  255. const dialogVisible = ref(false);
  256. // 设置分割样式
  257. const layoutUserFlexNum = computed(() => {
  258. let num: string | number;
  259. const { layout, isClassicSplitMenu } = themeConfig.value;
  260. const layoutArr: string[] = ['defaults', 'columns'];
  261. if (layoutArr.includes(layout) || (layout === 'classic' && !isClassicSplitMenu)) num = '1';
  262. else num = '';
  263. return num;
  264. });
  265. // 全屏点击时
  266. const onScreenfullClick = () => {
  267. if (!screenfull.isEnabled) {
  268. ElMessage.warning('暂不不支持全屏');
  269. return false;
  270. }
  271. screenfull.toggle();
  272. screenfull.on('change', () => {
  273. state.isScreenfull = screenfull.isFullscreen;
  274. });
  275. };
  276. // 布局配置 icon 点击时
  277. const onLayoutSetingClick = () => {
  278. mittBus.emit('openSetingsDrawer');
  279. };
  280. const dutyFormRef = ref<RefType>();
  281. // 下拉菜单点击时
  282. const onHandleCommandClick = (path: string) => {
  283. switch (path) {
  284. case 'changePwd': // 修改密码
  285. // 重置表单
  286. if (dutyFormRef.value) {
  287. dutyFormRef.value.resetFields();
  288. }
  289. showDutyDialog.value = true;
  290. break;
  291. case 'setting': // 设置
  292. onLayoutSetingClick();
  293. break;
  294. case 'search': // 搜索
  295. onSearchClick();
  296. break;
  297. case 'logOut': //退出登录
  298. if (telStatusInfo.value.isDutyOn) {
  299. ElMessageBox({
  300. closeOnClickModal: false,
  301. closeOnPressEscape: false,
  302. title: '提示',
  303. message: '检测到您未签出,本次退出系统将自动签出, 是否继续?',
  304. showCancelButton: true,
  305. confirmButtonText: '确定',
  306. cancelButtonText: '取消',
  307. buttonSize: 'default',
  308. draggable: true,
  309. type: 'warning',
  310. autofocus: false,
  311. cancelButtonClass: 'default-button',
  312. beforeClose: (action, instance, done) => {
  313. if (action === 'confirm') {
  314. instance.confirmButtonLoading = true;
  315. instance.confirmButtonText = '退出中';
  316. setTimeout(() => {
  317. done();
  318. setTimeout(() => {
  319. instance.confirmButtonLoading = false;
  320. }, 300);
  321. }, 700);
  322. } else {
  323. done();
  324. }
  325. },
  326. })
  327. .then(async () => {
  328. VoiceInterfaceObject.LogOut();
  329. // offDuty().then(() => {
  330. // 断开链接
  331. // signalR.stop();
  332. // 重置所有状态
  333. usetelStatusStore.resetState();
  334. // 清除缓存/token等
  335. Local.clear();
  336. Session.clear();
  337. Cookie.clear();
  338. // 使用 reload 时,不需要调用 resetRoute() 重置路由
  339. window.location.reload();
  340. // });
  341. })
  342. .catch(() => {});
  343. return;
  344. }
  345. ElMessageBox({
  346. closeOnClickModal: false,
  347. closeOnPressEscape: false,
  348. title: '提示',
  349. message: '此操作将退出登录, 是否继续?',
  350. showCancelButton: true,
  351. confirmButtonText: '确定',
  352. cancelButtonText: '取消',
  353. buttonSize: 'default',
  354. draggable: true,
  355. type: 'warning',
  356. autofocus: false,
  357. cancelButtonClass: 'default-button',
  358. beforeClose: (action, instance, done) => {
  359. if (action === 'confirm') {
  360. instance.confirmButtonLoading = true;
  361. instance.confirmButtonText = '退出中';
  362. setTimeout(() => {
  363. done();
  364. setTimeout(() => {
  365. instance.confirmButtonLoading = false;
  366. }, 300);
  367. }, 700);
  368. } else {
  369. done();
  370. }
  371. },
  372. })
  373. .then(async () => {
  374. // 清除缓存/token等
  375. Local.clear();
  376. Session.clear();
  377. Cookie.clear();
  378. // 使用 reload 时,不需要调用 resetRoute() 重置路由
  379. window.location.reload();
  380. })
  381. .catch(() => {});
  382. break;
  383. default: //返回首页
  384. router.push('/');
  385. break;
  386. }
  387. };
  388. // 菜单搜索点击
  389. const onSearchClick = () => {
  390. searchRef.value.openSearch();
  391. };
  392. // 组件大小改变
  393. const onComponentSizeChange = (size: string) => {
  394. Local.remove('themeConfig');
  395. themeConfig.value.globalComponentSize = size;
  396. Local.set('themeConfig', themeConfig.value);
  397. initComponentSize();
  398. window.location.reload();
  399. };
  400. // 初始化全局组件大小
  401. const initComponentSize = () => {
  402. switch (Local.get('themeConfig').globalComponentSize) {
  403. case 'large':
  404. state.disabledSize = 'large';
  405. break;
  406. case 'default':
  407. state.disabledSize = 'default';
  408. break;
  409. case 'small':
  410. state.disabledSize = 'small';
  411. break;
  412. }
  413. };
  414. const ruleFormRef = ref<RefType>();
  415. // 锁频
  416. const onLockScreen = () => {
  417. ruleFormRef.value?.resetFields();
  418. ruleFormRef.value?.resetFields();
  419. dialogVisible.value = true;
  420. };
  421. // 确定锁频
  422. const confirmLock = (formEl: FormInstance | undefined) => {
  423. if (!formEl) return;
  424. formEl.validate((valid: boolean) => {
  425. if (!valid) return;
  426. themeConfig.value.isLockScreen = true;
  427. Local.set('themeConfig', themeConfig.value);
  428. Session.set('lockPwd', state.ruleForm.pwd);
  429. dialogVisible.value = false;
  430. });
  431. };
  432. const showDutyDialog = ref(false);
  433. const loading = ref(false);
  434. // 修改密码保存
  435. const save = (formEl: FormInstance | undefined) => {
  436. if (!formEl) return;
  437. formEl.validate((valid: boolean) => {
  438. if (!valid) return;
  439. loading.value = true;
  440. changePwd(state.dutyForm)
  441. .then(async () => {
  442. ElNotification({
  443. title: '成功',
  444. type: 'success',
  445. message: '密码修改成功,请重新登录',
  446. });
  447. setTimeout(() => {
  448. loading.value = false;
  449. // 使用 reload 时,不需要调用 resetRoute() 重置路由
  450. window.location.reload();
  451. // 清楚缓存
  452. Session.clear();
  453. Cookie.clear();
  454. Local.clear();
  455. }, 1000);
  456. })
  457. .catch(() => {
  458. showDutyDialog.value = false;
  459. loading.value = false;
  460. });
  461. });
  462. };
  463. // 开发环境不显示设置
  464. const showSetting = computed(() => {
  465. return import.meta.env.VITE_MODE_NAME === 'development';
  466. });
  467. // 页面加载时
  468. onMounted(() => {
  469. if (Local.get('themeConfig')) {
  470. initComponentSize();
  471. }
  472. });
  473. </script>
  474. <style scoped lang="scss">
  475. .layout-navbars-breadcrumb-user {
  476. height: 100%;
  477. display: flex;
  478. align-items: center;
  479. justify-content: flex-end;
  480. &-link {
  481. height: 100%;
  482. white-space: nowrap;
  483. text-align: center;
  484. flex:1;
  485. &-photo {
  486. background-color: var(--hotline-bg-main-color);
  487. border: 2px solid var(--el-color-primary);
  488. margin-right: 5px;
  489. }
  490. &-photoBox {
  491. display: flex;
  492. justify-content: center;
  493. align-items: center;
  494. &-name{
  495. max-width: 150px;
  496. overflow: hidden;
  497. }
  498. }
  499. }
  500. &-icon {
  501. padding: 0 10px;
  502. cursor: pointer;
  503. color: var(--hotline-color-text-main);
  504. &:hover {
  505. i {
  506. display: inline-block;
  507. animation: logoAnimation 0.3s ease-in-out;
  508. }
  509. }
  510. }
  511. :deep(.el-dropdown) {
  512. color: var(--hotline-color-text-main);
  513. flex:1;
  514. }
  515. .intensity {
  516. .psdText {
  517. font-size: 14px;
  518. margin-right: 10px;
  519. color: #5a5a5a;
  520. }
  521. .line {
  522. display: inline-block;
  523. width: 48px;
  524. height: 10px;
  525. background: #d8d8d8;
  526. margin-right: 2px;
  527. &.ruo {
  528. border-radius: 6px 0 0 6px;
  529. }
  530. &.low {
  531. background: #bfcdff;
  532. }
  533. &.middle {
  534. background: #93a6fa;
  535. }
  536. &.high {
  537. background: #3c50e0;
  538. }
  539. &.qiang {
  540. border-radius: 0 6px 6px 0;
  541. }
  542. }
  543. .level {
  544. margin: 0 16px 0 8px;
  545. }
  546. }
  547. }
  548. </style>