header.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <template>
  2. <div class="flex">
  3. <el-popover placement="top" width="300">
  4. <div class="app-flex">
  5. <p
  6. class="appLink"
  7. v-for="app in menuApp"
  8. :key="app.index"
  9. @click="handelMenuAppClick(app, 'app')"
  10. >
  11. {{ app.systemappname }}
  12. </p>
  13. </div>
  14. <div slot="reference" class="search_panel">
  15. <input
  16. @focus="colorWhite = false"
  17. @blur="colorWhite = true"
  18. :placeholder="$t('输入搜索内容')"
  19. v-model="searchValue"
  20. />
  21. <i
  22. class="el-icon-search"
  23. :style="colorWhite ? 'color:#fff' : 'color:#000'"
  24. ></i>
  25. </div>
  26. </el-popover>
  27. <div class="right-operation flex-align-center">
  28. <!-- <div class="weather">
  29. <p>今日天气:{{weather.daily?weather.daily[0].dayText:""}}</p>
  30. <p>{{weather.daily?weather.daily[0].low:""}}℃ ~ {{weather.daily?weather.daily[0].high:""}}℃</p>
  31. </div> -->
  32. <!-- 语言 -->
  33. <!-- <el-dropdown @command="handleCommand">
  34. <span class="el-dropdown-link" style="color: #FFF;">
  35. 语言<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>
  36. </span>
  37. <el-dropdown-menu slot="dropdown">
  38. <el-dropdown-item v-for="item in langusge" :key="item.index" :command="item.languagecode">{{item.languagename}}</el-dropdown-item>
  39. </el-dropdown-menu>
  40. </el-dropdown>-->
  41. <!-- <el-divider direction="vertical"></el-divider>-->
  42. <el-button
  43. size="mint"
  44. type="primary"
  45. style="
  46. background-color: rgb(52 106 145);
  47. margin-right: 20px;
  48. color: #ffffff;
  49. "
  50. v-if="(usertype == 1 || usertype == 0) && (siteid == 'HY' || siteid == 'YOSTEST1')"
  51. @click="$router.push('/serviceDataScreen')"
  52. >{{ $t(`业务数据大屏`) }}</el-button
  53. >
  54. <svg
  55. t="1725853431060"
  56. class="icon"
  57. viewBox="0 0 1024 1024"
  58. version="1.1"
  59. xmlns="http://www.w3.org/2000/svg"
  60. p-id="9958"
  61. width="16"
  62. height="16"
  63. >
  64. <path
  65. d="M512 0a512 512 0 1 0 512 512A513.4848 513.4848 0 0 0 512 0z m371.2 262.4a467.968 467.968 0 0 1 76.8 217.6h-256A990.464 990.464 0 0 0 688.0256 307.2a1241.0368 1241.0368 0 0 0 195.1744-44.8zM838.4 204.8a1267.456 1267.456 0 0 1-166.4 38.4 1264.128 1264.128 0 0 0-51.2-166.4 454.1952 454.1952 0 0 1 217.6 128zM384 480a1396.1728 1396.1728 0 0 1 16.0256-166.4c35.2256 3.2256 73.6256 6.4 108.8 6.4 38.4 0 73.6256-3.1744 108.8-6.4a946.2784 946.2784 0 0 1 15.9744 166.4z m256 64a1396.1728 1396.1728 0 0 1-15.9744 166.4c-38.4-3.1744-73.5744-6.4-111.9744-6.4s-73.6256 3.2256-108.8 6.4a946.2784 946.2784 0 0 1-15.9744-166.4zM480 64h64a1058.1504 1058.1504 0 0 1 67.2256 185.6A533.7088 533.7088 0 0 1 512 256c-32 0-64-3.1744-96-3.1744a1089.8944 1089.8944 0 0 1 64-188.8256z m-76.8 12.8a843.6736 843.6736 0 0 0-51.2 166.4A1398.8352 1398.8352 0 0 1 185.6 204.8a454.1952 454.1952 0 0 1 217.6-128zM140.8 262.4A1241.0368 1241.0368 0 0 0 336.0256 307.2a990.464 990.464 0 0 0-15.9744 172.8h-256a455.68 455.68 0 0 1 76.8-217.6z m0 499.2a467.968 467.968 0 0 1-76.8-217.6h256A990.464 990.464 0 0 0 336.0256 716.8a1241.0368 1241.0368 0 0 0-195.2256 44.8zM185.6 819.2a1267.456 1267.456 0 0 1 166.4-38.4 1264.128 1264.128 0 0 0 51.2 166.4 454.1952 454.1952 0 0 1-217.6-128z m358.4 140.8h-64a1058.1504 1058.1504 0 0 1-67.1744-185.6c32-3.1744 64-3.1744 96-3.1744s64 3.2256 96 3.2256a900.7616 900.7616 0 0 1-60.7744 185.6z m76.8-12.8a843.6736 843.6736 0 0 0 51.2-166.4 1398.8352 1398.8352 0 0 1 166.4 38.4 454.1952 454.1952 0 0 1-217.6 128z m262.4-185.6A1241.0368 1241.0368 0 0 0 687.9744 716.8a990.464 990.464 0 0 0 16.0256-172.8h256a455.68 455.68 0 0 1-76.8 217.6z"
  66. fill="#FFFFFF"
  67. p-id="9959"
  68. ></path>
  69. </svg>
  70. <el-dropdown style="margin-left: 5px; margin-right: 30px">
  71. <!-- <el-button type="default" size="small" style="margin-right: 10px;">
  72. {{languagename}}<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>
  73. </el-button>-->
  74. <span class="el-dropdown-link">
  75. <div class="flex">
  76. {{ languagename }}<i class="el-icon-arrow-down el-icon--right"></i>
  77. </div>
  78. </span>
  79. <el-dropdown-menu slot="dropdown">
  80. <el-dropdown-item
  81. v-for="item in langusge"
  82. :key="item.index"
  83. @click.native="changeLanguage(item.languagecode)"
  84. >{{ item.languagename }}</el-dropdown-item
  85. >
  86. </el-dropdown-menu>
  87. </el-dropdown>
  88. <el-tooltip content="强制刷新配置" placement="bottom">
  89. <i
  90. class="el-icon-refresh"
  91. style="margin-left: 15px; margin-right: 15px; cursor: pointer; font-size: 16px"
  92. :class="{ 'is-loading': refreshing }"
  93. @click="refreshConfigs"
  94. ></i>
  95. </el-tooltip>
  96. <el-dropdown>
  97. <span class="el-dropdown-link">
  98. <div class="flex">
  99. {{ accountInfo.name }}-{{ accountInfo.sitename
  100. }}<i class="el-icon-arrow-down el-icon--right"></i>
  101. </div>
  102. </span>
  103. <el-dropdown-menu
  104. style="width: 200px; text-align: center"
  105. slot="dropdown"
  106. >
  107. <el-dropdown-item
  108. @click.native="$router.push({ path: '/user_center' })"
  109. >{{ $t("个人中心") }}</el-dropdown-item
  110. >
  111. <!-- <el-dropdown-item v-if="canChangeSite" @click.native="$router.replace({path:'/accounts'})">切换账号</el-dropdown-item> -->
  112. <el-dropdown-item
  113. v-for="item in accountList"
  114. :key="item.index"
  115. divided
  116. @click.native="selectAccount(item)"
  117. >
  118. <div class="flex-align-center flex-between">
  119. <p>
  120. <span class="avatar-mini">{{
  121. item.enterprisename
  122. ? item.enterprisename.substr(0, 1)
  123. : item.sitename.substr(0, 1)
  124. }}</span
  125. ><span>{{
  126. item.enterprisename ? item.enterprisename : item.sitename
  127. }}</span>
  128. </p>
  129. <small>{{ item.name }}</small>
  130. </div>
  131. </el-dropdown-item>
  132. <el-dropdown-item divided @click.native="loginOut()">{{
  133. $t("退出登录")
  134. }}</el-dropdown-item>
  135. </el-dropdown-menu>
  136. </el-dropdown>
  137. </div>
  138. </div>
  139. </template>
  140. <script>
  141. import {
  142. i18nGetResources,
  143. i18nChangeLanguage,
  144. i18nAddResources,
  145. } from "@wangeditor/editor";
  146. import { mapGetters } from "vuex";
  147. import axios from "axios";
  148. import Vue from "vue";
  149. export default {
  150. data() {
  151. return {
  152. accountInfo: {},
  153. url: "",
  154. weather: {},
  155. searchValue: "",
  156. accountList: [],
  157. colorWhite: true,
  158. langusge: [],
  159. nowType: "ZH",
  160. languagename: "",
  161. usertype: JSON.parse(sessionStorage.getItem("active_account")).usertype,
  162. siteid: JSON.parse(sessionStorage.getItem("active_account")).siteid,
  163. refreshing: false,
  164. };
  165. },
  166. props: ["onRender"],
  167. computed: {
  168. ...mapGetters({
  169. siteinfo: "siteinfo",
  170. menuApp: "menuApp",
  171. }),
  172. canChangeSite() {
  173. let accounts = JSON.parse(sessionStorage.getItem("account_list"));
  174. if (accounts.length > 1) return true;
  175. },
  176. },
  177. methods: {
  178. //修改富文本编辑器语言
  179. editorChangeLanguage() {
  180. console.log("zh-CN", i18nGetResources("zh-CN"));
  181. const types = {
  182. ZH: "zh-CN",
  183. EN: "en",
  184. };
  185. if (types[this.nowType]) {
  186. i18nChangeLanguage(types[this.nowType]);
  187. } else {
  188. let resources = i18nGetResources("zh-CN");
  189. const handleResources = (obj) => {
  190. for (const key in obj) {
  191. if (typeof obj[key] == "object") {
  192. handleResources(obj[key]);
  193. } else {
  194. obj[key] = this.$t(obj[key]);
  195. }
  196. }
  197. };
  198. handleResources(resources);
  199. i18nAddResources(this.nowType, resources);
  200. i18nChangeLanguage(this.nowType);
  201. }
  202. },
  203. // 选择登录账号
  204. async selectAccount(item) {
  205. let arr = ["module_info", "active_modules", "folderid"];
  206. arr.forEach((key) => {
  207. sessionStorage.removeItem(key);
  208. });
  209. sessionStorage.setItem("active_account", JSON.stringify(item));
  210. await this.basicData.query_userauth(() => {
  211. setTimeout(() => {
  212. this.$router.go(0);
  213. }, 1000);
  214. });
  215. this.siteInfos();
  216. this.accountInfo = JSON.parse(sessionStorage.getItem("active_account"));
  217. this.accountList = JSON.parse(
  218. sessionStorage.getItem("account_list")
  219. ).filter((e) => {
  220. return e.siteid !== this.accountInfo.siteid;
  221. });
  222. },
  223. async getWeather() {
  224. const res = await axios.get(this.url);
  225. this.weather = res.data.data;
  226. },
  227. siteInfos() {
  228. this.$store.dispatch("querySiteInfo", {
  229. classname: "webmanage.site.site",
  230. method: "querySite",
  231. content: {},
  232. });
  233. },
  234. loginOut() {
  235. this.$confirm(this.$t("是否要退出当前账号") + "?", this.$t("提示"), {
  236. confirmButtonText: this.$t("确定"),
  237. cancelButtonText: this.$t("取消"),
  238. type: "warning",
  239. })
  240. .then(() => {
  241. sessionStorage.clear();
  242. this.$router.push("/");
  243. location.reload();
  244. })
  245. .catch((err) => {
  246. console.log(err);
  247. this.$message({
  248. type: "info",
  249. message: this.$t("已取消"),
  250. });
  251. });
  252. },
  253. changeAccount() {
  254. this.$router.push("/accounts");
  255. },
  256. //跳转到应用,并设设置激活模块
  257. handelMenuAppClick(app, type) {
  258. let system = JSON.parse(sessionStorage.getItem("module_info"));
  259. let mod = system
  260. .filter((e) => {
  261. return e.systemid === app.systemid;
  262. })[0]
  263. .modules.filter((e) => {
  264. return e.systemmoduleid === app.systemmoduleid;
  265. })[0];
  266. let clickApp = mod.apps.filter((e) => {
  267. return e.systemappid === app.systemappid;
  268. });
  269. sessionStorage.setItem("active_modules", JSON.stringify(mod));
  270. this.$emit(
  271. "getModules",
  272. system.filter((e) => {
  273. return e.systemid === app.systemid;
  274. })[0].modules,
  275. type
  276. );
  277. this.$store.dispatch("setActiveApp", {
  278. name: app.systemappname,
  279. app: clickApp[0],
  280. val: this.searchValue,
  281. });
  282. this.$router.push({ path: clickApp[0].path });
  283. },
  284. async languagelist() {
  285. const res = await this.$api.requested({
  286. id: 10026401,
  287. });
  288. this.langusge = res.data;
  289. this.nowType = localStorage.getItem("lang")
  290. ? localStorage.getItem("lang")
  291. : "ZH";
  292. this.languagename =
  293. this.langusge.find((v) => v.languagecode == this.nowType)
  294. .languagename || "简体中文";
  295. localStorage.setItem("languagename", this.languagename);
  296. this.editorChangeLanguage();
  297. },
  298. async changeLanguage(type) {
  299. this.nowType = type;
  300. this.languagename =
  301. this.langusge.find((v) => v.languagecode == this.nowType)
  302. .languagename || "简体中文";
  303. localStorage.setItem("languagename", this.languagename);
  304. localStorage.setItem("lang", type);
  305. localStorage.setItem("languagename", this.languagename);
  306. this.$nextTick(() => {
  307. this.$i18n.locale = type;
  308. this.editorChangeLanguage();
  309. this.$api
  310. .requested({
  311. classname: "sysmanage.develop.userauthforweb.userauth",
  312. method: "query_userauth",
  313. content: {
  314. place: 1,
  315. date: Date.now(),
  316. },
  317. })
  318. .then((res) => {
  319. let active_modules = JSON.parse(
  320. sessionStorage.getItem("active_modules")
  321. );
  322. res.data.forEach((v) => {
  323. let item = v.modules.find((e) => {
  324. return e.systemmoduleid == active_modules.systemmoduleid;
  325. });
  326. if (item) {
  327. active_modules = item;
  328. try {
  329. let activeApp = item.apps.find(
  330. (v) =>
  331. v.systemappid == this.$store.getters.activeApp.systemappid
  332. );
  333. const link = () => {
  334. this.$router.push({ path: app.path });
  335. };
  336. this.$store.dispatch("setActiveApp", {
  337. name: activeApp.systemappname,
  338. app: activeApp,
  339. val: this.searchValue,
  340. link,
  341. });
  342. } catch (error) {}
  343. }
  344. });
  345. sessionStorage.setItem("module_info", JSON.stringify(res.data));
  346. sessionStorage.setItem(
  347. "active_modules",
  348. JSON.stringify(active_modules)
  349. );
  350. this.$emit("onRender");
  351. this.basicData.querySite_Parameter();
  352. });
  353. });
  354. },
  355. async refreshConfigs () {
  356. this.refreshing = true
  357. try {
  358. await this.basicData.refreshAllConfigs()
  359. this.$message.success('配置刷新成功')
  360. setTimeout(() => {
  361. this.$router.go(0)
  362. }, 300)
  363. } catch (e) {
  364. this.refreshing = false
  365. this.$message.error('配置刷新失败,请重试')
  366. }
  367. },
  368. },
  369. mounted() {
  370. this.siteInfos();
  371. this.languagelist();
  372. this.languagename = localStorage.getItem("languagename") ||"简体中文";
  373. try {
  374. this.languagename = localStorage.getItem("languagename") || "简体中文";
  375. } catch (error) {
  376. this.languagename = "简体中文";
  377. }
  378. this.accountInfo = JSON.parse(sessionStorage.getItem("active_account"));
  379. this.accountList = JSON.parse(
  380. sessionStorage.getItem("account_list")
  381. ).filter((e) => {
  382. return e.siteid !== this.accountInfo.siteid;
  383. });
  384. this.basicData.querySite_Parameter();
  385. },
  386. };
  387. </script>
  388. <style>
  389. .el-header {
  390. height: 50px !important;
  391. }
  392. .search_panel {
  393. position: relative;
  394. }
  395. .search_panel i {
  396. position: absolute;
  397. right: 0px;
  398. height: 30px;
  399. width: 30px;
  400. text-align: center;
  401. line-height: 30px;
  402. color: #333;
  403. }
  404. .search_panel input {
  405. background: rgba(255, 255, 255, 0.2);
  406. height: 30px;
  407. line-height: 30px;
  408. width: 300px;
  409. padding: 0 30px 0 20px;
  410. border: none;
  411. border-radius: 30px;
  412. color: #fff;
  413. outline: none;
  414. }
  415. .search_panel input::placeholder {
  416. color: #fff;
  417. }
  418. .search_panel input:focus {
  419. background: #fff;
  420. color: #333;
  421. }
  422. .search_panel input:focus::placeholder {
  423. color: #333;
  424. }
  425. </style>
  426. <style scoped>
  427. .flex {
  428. display: flex;
  429. align-items: center;
  430. justify-content: space-between;
  431. background: none;
  432. color: #fff;
  433. }
  434. .right-operation {
  435. padding: 0 20px;
  436. }
  437. .search_panel {
  438. margin: 16px 0;
  439. }
  440. .weather {
  441. font-size: 12px;
  442. margin-right: 16px;
  443. color: #f1f2f3;
  444. transition: 0.2s linear;
  445. border-radius: 4px;
  446. padding: 5px 40px;
  447. }
  448. .weather:hover {
  449. background-color: rgba(255, 255, 255, 0.2) !important;
  450. }
  451. .appLink {
  452. padding: 2px 5px;
  453. border: 1px solid #f1f2f3;
  454. border-radius: 5px;
  455. margin-bottom: 10px;
  456. margin-left: 5px;
  457. cursor: pointer;
  458. font-size: 12px;
  459. }
  460. .app-flex {
  461. display: flex;
  462. align-items: center;
  463. flex-wrap: wrap;
  464. }
  465. .avatar-mini {
  466. display: inline-block;
  467. position: relative;
  468. height: 20px;
  469. width: 20px;
  470. line-height: 20px;
  471. text-align: center;
  472. margin-right: 5px;
  473. color: #fff;
  474. font-size: 12px;
  475. font-weight: 500;
  476. border-radius: 100%;
  477. background: #3874f6;
  478. }
  479. .inactive {
  480. background: red !important;
  481. }
  482. </style>