header.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. export default {
  126. data() {
  127. return {
  128. accountInfo: {},
  129. url: "",
  130. weather: {},
  131. searchValue: "",
  132. accountList: [],
  133. colorWhite: true,
  134. langusge: [],
  135. nowType: "ZH",
  136. languagename: "",
  137. };
  138. },
  139. props: ["onRender"],
  140. computed: {
  141. ...mapGetters({
  142. siteinfo: "siteinfo",
  143. menuApp: "menuApp",
  144. }),
  145. canChangeSite() {
  146. let accounts = JSON.parse(sessionStorage.getItem("account_list"));
  147. if (accounts.length > 1) return true;
  148. },
  149. },
  150. methods: {
  151. // 选择登录账号
  152. async selectAccount(item) {
  153. let arr = ["module_info", "active_modules", "folderid"];
  154. arr.forEach((key) => {
  155. sessionStorage.removeItem(key);
  156. });
  157. sessionStorage.setItem("active_account", JSON.stringify(item));
  158. this.siteInfos();
  159. this.accountInfo = JSON.parse(sessionStorage.getItem("active_account"));
  160. this.accountList = JSON.parse(
  161. sessionStorage.getItem("account_list")
  162. ).filter((e) => {
  163. return e.siteid !== this.accountInfo.siteid;
  164. });
  165. },
  166. async getWeather() {
  167. const res = await axios.get(this.url);
  168. this.weather = res.data.data;
  169. },
  170. siteInfos() {
  171. this.$store.dispatch("querySiteInfo", {
  172. classname: "webmanage.site.site",
  173. method: "querySite",
  174. content: {},
  175. });
  176. },
  177. loginOut() {
  178. let lang = localStorage.getItem("lang");
  179. this.$confirm(this.$t("是否要退出当前账号") + "?", this.$t("提示"), {
  180. confirmButtonText: this.$t("确定"),
  181. cancelButtonText: this.$t("取消"),
  182. type: "warning",
  183. })
  184. .then(() => {
  185. sessionStorage.clear();
  186. localStorage.setItem("lang", lang);
  187. this.$router.push("/");
  188. location.reload();
  189. })
  190. .catch((err) => {
  191. console.log(err);
  192. this.$message({
  193. type: "info",
  194. message: this.$t("已取消"),
  195. });
  196. });
  197. },
  198. changeAccount() {
  199. this.$router.push("/accounts");
  200. },
  201. //跳转到应用,并设设置激活模块
  202. handelMenuAppClick(app, type) {
  203. let system = JSON.parse(sessionStorage.getItem("module_info"));
  204. let mod = system
  205. .filter((e) => {
  206. return e.systemid === app.systemid;
  207. })[0]
  208. .modules.filter((e) => {
  209. return e.systemmoduleid === app.systemmoduleid;
  210. })[0];
  211. let clickApp = mod.apps.filter((e) => {
  212. return e.systemappid === app.systemappid;
  213. });
  214. sessionStorage.setItem("active_modules", JSON.stringify(mod));
  215. this.$emit(
  216. "getModules",
  217. system.filter((e) => {
  218. return e.systemid === app.systemid;
  219. })[0].modules,
  220. type
  221. );
  222. this.$store.dispatch("setActiveApp", {
  223. name: app.systemappname,
  224. app: clickApp[0],
  225. val: this.searchValue,
  226. });
  227. //activeApp
  228. this.$router.push({ path: clickApp[0].path });
  229. },
  230. async languagelist() {
  231. const res = await this.$api.requested({
  232. id: 10026401,
  233. });
  234. this.langusge = res.data;
  235. this.nowType = localStorage.getItem("lang")
  236. ? localStorage.getItem("lang")
  237. : "ZH";
  238. this.languagename =
  239. this.langusge.find((v) => v.languagecode == this.nowType)
  240. .languagename || "简体中文";
  241. },
  242. async i18nChangeLanguage(type) {
  243. this.nowType = type;
  244. this.languagename =
  245. this.langusge.find((v) => v.languagecode == this.nowType)
  246. .languagename || "简体中文";
  247. localStorage.setItem("lang", type);
  248. this.$nextTick(() => {
  249. this.$i18n.locale = type;
  250. this.$api
  251. .requested({
  252. classname: "sysmanage.develop.userauthforweb.userauth",
  253. method: "query_userauth",
  254. content: {
  255. place: 1,
  256. date: Date.now(),
  257. },
  258. })
  259. .then((res) => {
  260. let active_modules = JSON.parse(
  261. sessionStorage.getItem("active_modules")
  262. );
  263. res.data.forEach((v) => {
  264. let item = v.modules.find((e) => {
  265. return e.systemmoduleid == active_modules.systemmoduleid;
  266. });
  267. if (item) {
  268. active_modules = item;
  269. try {
  270. let activeApp = item.apps.find(
  271. (v) =>
  272. v.systemmoduleid ==
  273. this.$store.getters.activeApp.systemmoduleid
  274. );
  275. this.$store.commit("activeApp", activeApp);
  276. } catch (error) {}
  277. }
  278. });
  279. sessionStorage.setItem("module_info", JSON.stringify(res.data));
  280. sessionStorage.setItem(
  281. "active_modules",
  282. JSON.stringify(active_modules)
  283. );
  284. this.basicData.querySite_Parameter();
  285. this.$emit("onRender");
  286. });
  287. });
  288. },
  289. },
  290. mounted() {
  291. this.siteInfos();
  292. this.languagelist();
  293. this.accountInfo = JSON.parse(sessionStorage.getItem("active_account"));
  294. this.accountList = JSON.parse(
  295. sessionStorage.getItem("account_list")
  296. ).filter((e) => {
  297. return e.siteid !== this.accountInfo.siteid;
  298. });
  299. this.basicData.querySite_Parameter();
  300. },
  301. };
  302. </script>
  303. <style>
  304. .el-header {
  305. height: 50px !important;
  306. }
  307. .search_panel {
  308. position: relative;
  309. }
  310. .search_panel i {
  311. position: absolute;
  312. right: 0px;
  313. height: 30px;
  314. width: 30px;
  315. text-align: center;
  316. line-height: 30px;
  317. color: #333;
  318. }
  319. .search_panel input {
  320. background: rgba(255, 255, 255, 0.2);
  321. height: 30px;
  322. line-height: 30px;
  323. width: 300px;
  324. padding: 0 30px 0 20px;
  325. border: none;
  326. border-radius: 30px;
  327. color: #fff;
  328. outline: none;
  329. }
  330. .search_panel input::placeholder {
  331. color: #fff;
  332. }
  333. .search_panel input:focus {
  334. background: #fff;
  335. color: #333;
  336. }
  337. .search_panel input:focus::placeholder {
  338. color: #333;
  339. }
  340. </style>
  341. <style scoped>
  342. .flex {
  343. display: flex;
  344. align-items: center;
  345. justify-content: space-between;
  346. background: none;
  347. color: #fff;
  348. }
  349. .right-operation {
  350. padding: 0 20px;
  351. }
  352. .search_panel {
  353. margin: 16px 0;
  354. }
  355. .weather {
  356. font-size: 12px;
  357. margin-right: 16px;
  358. color: #f1f2f3;
  359. transition: 0.2s linear;
  360. border-radius: 4px;
  361. padding: 5px 40px;
  362. }
  363. .weather:hover {
  364. background-color: rgba(255, 255, 255, 0.2) !important;
  365. }
  366. .appLink {
  367. padding: 2px 5px;
  368. border: 1px solid #f1f2f3;
  369. border-radius: 5px;
  370. margin-bottom: 10px;
  371. margin-left: 5px;
  372. cursor: pointer;
  373. font-size: 12px;
  374. }
  375. .app-flex {
  376. display: flex;
  377. align-items: center;
  378. flex-wrap: wrap;
  379. }
  380. .avatar-mini {
  381. display: inline-block;
  382. position: relative;
  383. height: 20px;
  384. width: 20px;
  385. line-height: 20px;
  386. text-align: center;
  387. margin-right: 5px;
  388. color: #fff;
  389. font-size: 12px;
  390. font-weight: 500;
  391. border-radius: 100%;
  392. background: #3874f6;
  393. }
  394. .inactive {
  395. background: red !important;
  396. }
  397. </style>