header.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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 size="mint" type="primary" style="background-color:rgb(52 106 145);margin-right: 20px;color: #FFFFFF" v-if="(usertype == 1 || usertype == 0) && siteid == 'HY'" @click="$router.push('/serviceDataScreen')">{{$t(`业务数据大屏`)}}</el-button>
  43. <svg
  44. t="1725853431060"
  45. class="icon"
  46. viewBox="0 0 1024 1024"
  47. version="1.1"
  48. xmlns="http://www.w3.org/2000/svg"
  49. p-id="9958"
  50. width="16"
  51. height="16"
  52. >
  53. <path
  54. 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"
  55. fill="#FFFFFF"
  56. p-id="9959"
  57. ></path>
  58. </svg>
  59. <el-dropdown style="margin-left: 5px; margin-right: 30px">
  60. <!-- <el-button type="default" size="small" style="margin-right: 10px;">
  61. {{languagename}}<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>
  62. </el-button>-->
  63. <span class="el-dropdown-link">
  64. <div class="flex">
  65. {{ languagename }}<i class="el-icon-arrow-down el-icon--right"></i>
  66. </div>
  67. </span>
  68. <el-dropdown-menu slot="dropdown">
  69. <el-dropdown-item
  70. v-for="item in langusge"
  71. :key="item.index"
  72. @click.native="changeLanguage(item.languagecode)"
  73. >{{ item.languagename }}</el-dropdown-item
  74. >
  75. </el-dropdown-menu>
  76. </el-dropdown>
  77. <el-dropdown>
  78. <span class="el-dropdown-link">
  79. <div class="flex">
  80. {{ accountInfo.name }}-{{ accountInfo.sitename
  81. }}<i class="el-icon-arrow-down el-icon--right"></i>
  82. </div>
  83. </span>
  84. <el-dropdown-menu
  85. style="width: 200px; text-align: center"
  86. slot="dropdown"
  87. >
  88. <el-dropdown-item
  89. @click.native="$router.push({ path: '/user_center' })"
  90. >{{ $t("个人中心") }}</el-dropdown-item
  91. >
  92. <!-- <el-dropdown-item v-if="canChangeSite" @click.native="$router.replace({path:'/accounts'})">切换账号</el-dropdown-item> -->
  93. <el-dropdown-item
  94. v-for="item in accountList"
  95. :key="item.index"
  96. divided
  97. @click.native="selectAccount(item)"
  98. >
  99. <div class="flex-align-center flex-between">
  100. <p>
  101. <span class="avatar-mini">{{
  102. item.enterprisename
  103. ? item.enterprisename.substr(0, 1)
  104. : item.sitename.substr(0, 1)
  105. }}</span
  106. ><span>{{
  107. item.enterprisename ? item.enterprisename : item.sitename
  108. }}</span>
  109. </p>
  110. <small>{{ item.name }}</small>
  111. </div>
  112. </el-dropdown-item>
  113. <el-dropdown-item divided @click.native="loginOut()">{{
  114. $t("退出登录")
  115. }}</el-dropdown-item>
  116. </el-dropdown-menu>
  117. </el-dropdown>
  118. </div>
  119. </div>
  120. </template>
  121. <script>
  122. import {
  123. i18nGetResources,
  124. i18nChangeLanguage,
  125. i18nAddResources,
  126. } from "@wangeditor/editor";
  127. import { mapGetters } from "vuex";
  128. import axios from "axios";
  129. import Vue from "vue";
  130. export default {
  131. data() {
  132. return {
  133. accountInfo: {},
  134. url: "",
  135. weather: {},
  136. searchValue: "",
  137. accountList: [],
  138. colorWhite: true,
  139. langusge: [],
  140. nowType: "ZH",
  141. languagename: "",
  142. usertype: JSON.parse(sessionStorage.getItem("active_account")).usertype,
  143. siteid: JSON.parse(sessionStorage.getItem('active_account')).siteid
  144. };
  145. },
  146. props: ["onRender"],
  147. computed: {
  148. ...mapGetters({
  149. siteinfo: "siteinfo",
  150. menuApp: "menuApp",
  151. }),
  152. canChangeSite() {
  153. let accounts = JSON.parse(sessionStorage.getItem("account_list"));
  154. if (accounts.length > 1) return true;
  155. },
  156. },
  157. methods: {
  158. //修改富文本编辑器语言
  159. editorChangeLanguage() {
  160. console.log("zh-CN", i18nGetResources("zh-CN"));
  161. const types = {
  162. ZH: "zh-CN",
  163. EN: "en",
  164. };
  165. if (types[this.nowType]) {
  166. i18nChangeLanguage(types[this.nowType]);
  167. } else {
  168. let resources = i18nGetResources("zh-CN");
  169. const handleResources = (obj) => {
  170. for (const key in obj) {
  171. if (typeof obj[key] == "object") {
  172. handleResources(obj[key]);
  173. } else {
  174. obj[key] = this.$t(obj[key]);
  175. }
  176. }
  177. };
  178. handleResources(resources);
  179. i18nAddResources(this.nowType, resources);
  180. i18nChangeLanguage(this.nowType);
  181. }
  182. },
  183. // 选择登录账号
  184. async selectAccount(item) {
  185. let arr = ["module_info", "active_modules", "folderid"];
  186. arr.forEach((key) => {
  187. sessionStorage.removeItem(key);
  188. });
  189. sessionStorage.setItem("active_account", JSON.stringify(item));
  190. await this.basicData.query_userauth(() => {
  191. setTimeout(() => {
  192. console.log("33333");
  193. this.$router.go(0);
  194. }, 1000);
  195. });
  196. this.siteInfos();
  197. this.accountInfo = JSON.parse(sessionStorage.getItem("active_account"));
  198. this.accountList = JSON.parse(
  199. sessionStorage.getItem("account_list")
  200. ).filter((e) => {
  201. return e.siteid !== this.accountInfo.siteid;
  202. });
  203. },
  204. async getWeather() {
  205. const res = await axios.get(this.url);
  206. this.weather = res.data.data;
  207. },
  208. siteInfos() {
  209. this.$store.dispatch("querySiteInfo", {
  210. classname: "webmanage.site.site",
  211. method: "querySite",
  212. content: {},
  213. });
  214. },
  215. loginOut() {
  216. let lang = localStorage.getItem("lang");
  217. this.$confirm(this.$t("是否要退出当前账号") + "?", this.$t("提示"), {
  218. confirmButtonText: this.$t("确定"),
  219. cancelButtonText: this.$t("取消"),
  220. type: "warning",
  221. })
  222. .then(() => {
  223. sessionStorage.clear();
  224. localStorage.setItem("lang", lang);
  225. this.$router.push("/");
  226. location.reload();
  227. })
  228. .catch((err) => {
  229. console.log(err);
  230. this.$message({
  231. type: "info",
  232. message: this.$t("已取消"),
  233. });
  234. });
  235. },
  236. changeAccount() {
  237. this.$router.push("/accounts");
  238. },
  239. //跳转到应用,并设设置激活模块
  240. handelMenuAppClick(app, type) {
  241. let system = JSON.parse(sessionStorage.getItem("module_info"));
  242. let mod = system
  243. .filter((e) => {
  244. return e.systemid === app.systemid;
  245. })[0]
  246. .modules.filter((e) => {
  247. return e.systemmoduleid === app.systemmoduleid;
  248. })[0];
  249. let clickApp = mod.apps.filter((e) => {
  250. return e.systemappid === app.systemappid;
  251. });
  252. sessionStorage.setItem("active_modules", JSON.stringify(mod));
  253. this.$emit(
  254. "getModules",
  255. system.filter((e) => {
  256. return e.systemid === app.systemid;
  257. })[0].modules,
  258. type
  259. );
  260. this.$store.dispatch("setActiveApp", {
  261. name: app.systemappname,
  262. app: clickApp[0],
  263. val: this.searchValue,
  264. });
  265. this.$router.push({ path: clickApp[0].path });
  266. },
  267. async languagelist() {
  268. const res = await this.$api.requested({
  269. id: 10026401,
  270. });
  271. this.langusge = res.data;
  272. this.nowType = localStorage.getItem("lang")
  273. ? localStorage.getItem("lang")
  274. : "ZH";
  275. this.languagename =
  276. this.langusge.find((v) => v.languagecode == this.nowType)
  277. .languagename || "简体中文";
  278. this.editorChangeLanguage();
  279. },
  280. async changeLanguage(type) {
  281. this.nowType = type;
  282. this.languagename =
  283. this.langusge.find((v) => v.languagecode == this.nowType)
  284. .languagename || "简体中文";
  285. localStorage.setItem("lang", type);
  286. this.$nextTick(() => {
  287. this.$i18n.locale = type;
  288. this.editorChangeLanguage();
  289. this.$api
  290. .requested({
  291. classname: "sysmanage.develop.userauthforweb.userauth",
  292. method: "query_userauth",
  293. content: {
  294. place: 1,
  295. date: Date.now(),
  296. },
  297. })
  298. .then((res) => {
  299. let active_modules = JSON.parse(
  300. sessionStorage.getItem("active_modules")
  301. );
  302. res.data.forEach((v) => {
  303. let item = v.modules.find((e) => {
  304. return e.systemmoduleid == active_modules.systemmoduleid;
  305. });
  306. if (item) {
  307. active_modules = item;
  308. try {
  309. let activeApp = item.apps.find(
  310. (v) =>
  311. v.systemappid == this.$store.getters.activeApp.systemappid
  312. );
  313. const link = () => {
  314. this.$router.push({ path: app.path });
  315. };
  316. this.$store.dispatch("setActiveApp", {
  317. name: activeApp.systemappname,
  318. app: activeApp,
  319. val: this.searchValue,
  320. link,
  321. });
  322. } catch (error) {}
  323. }
  324. });
  325. sessionStorage.setItem("module_info", JSON.stringify(res.data));
  326. sessionStorage.setItem(
  327. "active_modules",
  328. JSON.stringify(active_modules)
  329. );
  330. this.$emit("onRender");
  331. this.basicData.querySite_Parameter();
  332. });
  333. });
  334. },
  335. },
  336. mounted() {
  337. this.siteInfos();
  338. this.languagelist();
  339. this.accountInfo = JSON.parse(sessionStorage.getItem("active_account"));
  340. this.accountList = JSON.parse(
  341. sessionStorage.getItem("account_list")
  342. ).filter((e) => {
  343. return e.siteid !== this.accountInfo.siteid;
  344. });
  345. this.basicData.querySite_Parameter();
  346. },
  347. };
  348. </script>
  349. <style>
  350. .el-header {
  351. height: 50px !important;
  352. }
  353. .search_panel {
  354. position: relative;
  355. }
  356. .search_panel i {
  357. position: absolute;
  358. right: 0px;
  359. height: 30px;
  360. width: 30px;
  361. text-align: center;
  362. line-height: 30px;
  363. color: #333;
  364. }
  365. .search_panel input {
  366. background: rgba(255, 255, 255, 0.2);
  367. height: 30px;
  368. line-height: 30px;
  369. width: 300px;
  370. padding: 0 30px 0 20px;
  371. border: none;
  372. border-radius: 30px;
  373. color: #fff;
  374. outline: none;
  375. }
  376. .search_panel input::placeholder {
  377. color: #fff;
  378. }
  379. .search_panel input:focus {
  380. background: #fff;
  381. color: #333;
  382. }
  383. .search_panel input:focus::placeholder {
  384. color: #333;
  385. }
  386. </style>
  387. <style scoped>
  388. .flex {
  389. display: flex;
  390. align-items: center;
  391. justify-content: space-between;
  392. background: none;
  393. color: #fff;
  394. }
  395. .right-operation {
  396. padding: 0 20px;
  397. }
  398. .search_panel {
  399. margin: 16px 0;
  400. }
  401. .weather {
  402. font-size: 12px;
  403. margin-right: 16px;
  404. color: #f1f2f3;
  405. transition: 0.2s linear;
  406. border-radius: 4px;
  407. padding: 5px 40px;
  408. }
  409. .weather:hover {
  410. background-color: rgba(255, 255, 255, 0.2) !important;
  411. }
  412. .appLink {
  413. padding: 2px 5px;
  414. border: 1px solid #f1f2f3;
  415. border-radius: 5px;
  416. margin-bottom: 10px;
  417. margin-left: 5px;
  418. cursor: pointer;
  419. font-size: 12px;
  420. }
  421. .app-flex {
  422. display: flex;
  423. align-items: center;
  424. flex-wrap: wrap;
  425. }
  426. .avatar-mini {
  427. display: inline-block;
  428. position: relative;
  429. height: 20px;
  430. width: 20px;
  431. line-height: 20px;
  432. text-align: center;
  433. margin-right: 5px;
  434. color: #fff;
  435. font-size: 12px;
  436. font-weight: 500;
  437. border-radius: 100%;
  438. background: #3874f6;
  439. }
  440. .inactive {
  441. background: red !important;
  442. }
  443. </style>