header.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. <svg
  43. t="1725853431060"
  44. class="icon"
  45. viewBox="0 0 1024 1024"
  46. version="1.1"
  47. xmlns="http://www.w3.org/2000/svg"
  48. p-id="9958"
  49. width="16"
  50. height="16"
  51. >
  52. <path
  53. 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"
  54. fill="#FFFFFF"
  55. p-id="9959"
  56. ></path>
  57. </svg>
  58. <el-dropdown style="margin-left: 5px; margin-right: 30px">
  59. <!-- <el-button type="default" size="small" style="margin-right: 10px;">
  60. {{languagename}}<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>
  61. </el-button>-->
  62. <span class="el-dropdown-link">
  63. <div class="flex">
  64. {{ languagename }}<i class="el-icon-arrow-down el-icon--right"></i>
  65. </div>
  66. </span>
  67. <el-dropdown-menu slot="dropdown">
  68. <el-dropdown-item
  69. v-for="item in langusge"
  70. :key="item.index"
  71. @click.native="i18nChangeLanguage(item.languagecode)"
  72. >{{ item.languagename }}</el-dropdown-item
  73. >
  74. <!-- <el-dropdown-item @click.native="i18nChangeLanguage('EN')">English</el-dropdown-item> -->
  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 { mapGetters } from "vuex";
  123. import axios from "axios";
  124. import Vue from "vue";
  125. import enLocale from "element-ui/lib/locale/lang/en";
  126. import zhLocale from "element-ui/lib/locale/lang/zh-CN";
  127. import ruLocale from "element-ui/lib/locale/lang/ru-RU";
  128. export default {
  129. data() {
  130. return {
  131. accountInfo: {},
  132. url: "",
  133. weather: {},
  134. searchValue: "",
  135. accountList: [],
  136. colorWhite: true,
  137. langusge: [],
  138. nowType: "ZH",
  139. languagename: "",
  140. };
  141. },
  142. computed: {
  143. ...mapGetters({
  144. siteinfo: "siteinfo",
  145. menuApp: "menuApp",
  146. }),
  147. canChangeSite() {
  148. let accounts = JSON.parse(sessionStorage.getItem("account_list"));
  149. if (accounts.length > 1) return true;
  150. },
  151. },
  152. methods: {
  153. // 选择登录账号
  154. async selectAccount(item) {
  155. let arr = ["module_info", "activeApp", "active_modules", "folderid"];
  156. arr.forEach((key) => {
  157. sessionStorage.removeItem(key);
  158. });
  159. sessionStorage.setItem("active_account", JSON.stringify(item));
  160. await this.basicData.query_userauth();
  161. this.siteInfos();
  162. this.accountInfo = JSON.parse(sessionStorage.getItem("active_account"));
  163. this.accountList = JSON.parse(
  164. sessionStorage.getItem("account_list")
  165. ).filter((e) => {
  166. return e.siteid !== this.accountInfo.siteid;
  167. });
  168. this.$nextTick(() => {
  169. this.$router.go(0);
  170. });
  171. },
  172. async getWeather() {
  173. const res = await axios.get(this.url);
  174. this.weather = res.data.data;
  175. },
  176. siteInfos() {
  177. this.$store.dispatch("querySiteInfo", {
  178. classname: "webmanage.site.site",
  179. method: "querySite",
  180. content: {},
  181. });
  182. },
  183. loginOut() {
  184. let lang = sessionStorage.getItem("lang");
  185. this.$confirm(this.$t("是否要退出当前账号") + "?", this.$t("提示"), {
  186. confirmButtonText: this.$t("确定"),
  187. cancelButtonText: this.$t("取消"),
  188. type: "warning",
  189. })
  190. .then(() => {
  191. sessionStorage.clear();
  192. sessionStorage.setItem("lang", lang);
  193. this.$router.push("/");
  194. location.reload();
  195. })
  196. .catch((err) => {
  197. console.log(err);
  198. this.$message({
  199. type: "info",
  200. message: this.$t("已取消"),
  201. });
  202. });
  203. },
  204. changeAccount() {
  205. this.$router.push("/accounts");
  206. },
  207. handleCommand(command) {
  208. sessionStorage.setItem("lang", command);
  209. this.basicData.query_userauth().then(() => {
  210. this.$router.go(0);
  211. });
  212. },
  213. //跳转到应用,并设设置激活模块
  214. handelMenuAppClick(app, type) {
  215. let system = JSON.parse(sessionStorage.getItem("module_info"));
  216. let mod = system
  217. .filter((e) => {
  218. return e.systemid === app.systemid;
  219. })[0]
  220. .modules.filter((e) => {
  221. return e.systemmoduleid === app.systemmoduleid;
  222. })[0];
  223. let clickApp = mod.apps.filter((e) => {
  224. return e.systemappid === app.systemappid;
  225. });
  226. sessionStorage.setItem("active_modules", JSON.stringify(mod));
  227. this.$emit(
  228. "getModules",
  229. system.filter((e) => {
  230. return e.systemid === app.systemid;
  231. })[0].modules,
  232. type
  233. );
  234. this.$store.dispatch("setActiveApp", {
  235. name: app.systemappname,
  236. app: clickApp[0],
  237. val: this.searchValue,
  238. });
  239. this.$router.push({ path: clickApp[0].path });
  240. },
  241. async languagelist() {
  242. const res = await this.$api.requested({
  243. id: 10026401,
  244. });
  245. this.langusge = res.data;
  246. this.nowType = sessionStorage.getItem("lang")
  247. ? sessionStorage.getItem("lang")
  248. : "ZH";
  249. },
  250. async i18nChangeLanguage(type) {
  251. sessionStorage.setItem("lang", type);
  252. await this.basicData.query_userauth();
  253. this.$router.go(0);
  254. },
  255. async qusetLanguage() {
  256. this.nowType = sessionStorage.getItem('lang').toUpperCase()
  257. const res = await this.$api.requested({
  258. id: 2024062809072801,
  259. content: {
  260. languagecode: this.nowType,
  261. },
  262. });
  263. switch (this.nowType) {
  264. case "EN":
  265. Vue.config.lang = "en";
  266. Vue.locale("en", Object.assign(enLocale, res.data.EN));
  267. break;
  268. case "RU":
  269. Vue.config.lang = "ru-RU";
  270. Vue.locale("ru-RU", Object.assign(ruLocale, res.data.RU));
  271. break;
  272. default:
  273. Vue.config.lang = "zh-cn";
  274. Vue.locale("zh-cn", Object.assign(zhLocale));
  275. break;
  276. }
  277. this.languagename = this.langusge.filter(
  278. (e) => e.languagecode == this.nowType
  279. )[0].languagename;
  280. },
  281. },
  282. mounted() {
  283. this.siteInfos();
  284. this.languagelist();
  285. this.accountInfo = JSON.parse(sessionStorage.getItem("active_account"));
  286. this.accountList = JSON.parse(
  287. sessionStorage.getItem("account_list")
  288. ).filter((e) => {
  289. return e.siteid !== this.accountInfo.siteid;
  290. });
  291. this.basicData.querySite_Parameter();
  292. this.qusetLanguage();
  293. },
  294. };
  295. </script>
  296. <style>
  297. .el-header {
  298. height: 50px !important;
  299. }
  300. .search_panel {
  301. position: relative;
  302. }
  303. .search_panel i {
  304. position: absolute;
  305. right: 0px;
  306. height: 30px;
  307. width: 30px;
  308. text-align: center;
  309. line-height: 30px;
  310. color: #333;
  311. }
  312. .search_panel input {
  313. background: rgba(255, 255, 255, 0.2);
  314. height: 30px;
  315. line-height: 30px;
  316. width: 300px;
  317. padding: 0 30px 0 20px;
  318. border: none;
  319. border-radius: 30px;
  320. color: #fff;
  321. outline: none;
  322. }
  323. .search_panel input::placeholder {
  324. color: #fff;
  325. }
  326. .search_panel input:focus {
  327. background: #fff;
  328. color: #333;
  329. }
  330. .search_panel input:focus::placeholder {
  331. color: #333;
  332. }
  333. </style>
  334. <style scoped>
  335. .flex {
  336. display: flex;
  337. align-items: center;
  338. justify-content: space-between;
  339. background: none;
  340. color: #fff;
  341. }
  342. .right-operation {
  343. padding: 0 20px;
  344. }
  345. .search_panel {
  346. margin: 16px 0;
  347. }
  348. .weather {
  349. font-size: 12px;
  350. margin-right: 16px;
  351. color: #f1f2f3;
  352. transition: 0.2s linear;
  353. border-radius: 4px;
  354. padding: 5px 40px;
  355. }
  356. .weather:hover {
  357. background-color: rgba(255, 255, 255, 0.2) !important;
  358. }
  359. .appLink {
  360. padding: 2px 5px;
  361. border: 1px solid #f1f2f3;
  362. border-radius: 5px;
  363. margin-bottom: 10px;
  364. margin-left: 5px;
  365. cursor: pointer;
  366. font-size: 12px;
  367. }
  368. .app-flex {
  369. display: flex;
  370. align-items: center;
  371. flex-wrap: wrap;
  372. }
  373. .avatar-mini {
  374. display: inline-block;
  375. position: relative;
  376. height: 20px;
  377. width: 20px;
  378. line-height: 20px;
  379. text-align: center;
  380. margin-right: 5px;
  381. color: #fff;
  382. font-size: 12px;
  383. font-weight: 500;
  384. border-radius: 100%;
  385. background: #3874f6;
  386. }
  387. .inactive {
  388. background: red !important;
  389. }
  390. </style>