NewIndex.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <div class="common-layout">
  3. <TopMenu
  4. @openMaxmin="openMaxmin"
  5. @goIndex="goIndex"
  6. :systemPath="systemPath"
  7. :hasRole="hasRole"
  8. ></TopMenu>
  9. <DefaultPage
  10. :showSearch="showSearch"
  11. :hightData="hightData"
  12. :allData="allData"
  13. :hightDataTotal="hightDataTotal"
  14. :allDataTotal="allDataTotal"
  15. @changeSearch="changeSearch"
  16. @openMaxmin="openMaxmin"
  17. ></DefaultPage>
  18. <div class="footer"></div>
  19. </div>
  20. </template>
  21. <script setup>
  22. import { onMounted, ref, provide, onUnmounted } from "vue";
  23. import bus from "@/utils/bus.js";
  24. import TopMenu from "@/layout/components/TopMenu/TopMenu.vue";
  25. import DefaultPage from "@/layout/components/DefaultPage/DefaultPage.vue";
  26. import { layer } from "@layui/layer-vue";
  27. import { ElMessage, ElLoading, ElMessageBox } from "element-plus";
  28. import useUserStore from "@/store/modules/user";
  29. import usePermissionStore from "@/store/modules/permission";
  30. import { searchAll } from "@/api/search/search.js";
  31. import { flieSearch } from "@/api/search/search.js";
  32. const permissionStore = usePermissionStore();
  33. const sidebarRouters = computed(() => permissionStore.sidebarRouters);
  34. const roles = useUserStore().roles;
  35. const permissionRoles = ["admin", "dept", "system", "audit"];
  36. const super_admin = "admin";
  37. const hasRole = ref(
  38. roles.some((role) => {
  39. return super_admin === role || permissionRoles.includes(role);
  40. })
  41. );
  42. const showSearch = ref(false); //是否显示搜索结果界面
  43. const systemPath = ref({});
  44. const searchText = ref(""); //搜索框的值
  45. const hightData = ref([]); // 高级搜索数据
  46. const allData = ref([]); // 全域搜索数据
  47. const hightDataTotal = ref(); // 高级搜索数据总数
  48. const allDataTotal = ref(); // 全域搜索数据总数
  49. // 将标签信息保存到本地
  50. const openMaxmin = (title, path) => {
  51. const item = {
  52. title: title,
  53. path: path,
  54. };
  55. // 判断是否存在标签列表,存在则添加,不存在则创建
  56. const storage = sessionStorage.getItem("tagList");
  57. if (storage) {
  58. //如果标签数量超过11个,提示超出最大限制
  59. if (JSON.parse(storage).length >= 10) {
  60. ElMessage({ message: "标签数量超出最大限制", type: "error" });
  61. return;
  62. }
  63. const oldStorage = JSON.parse(storage);
  64. // 判断是否存在相同的标签
  65. if (oldStorage.find((item) => item.path === path)) {
  66. ElMessage({ message: "该页面已经打开", type: "info" });
  67. return;
  68. }
  69. const thisId = layer.open({
  70. type: "iframe", //类型
  71. // move: true, //拖拽
  72. maxmin: true,
  73. moveOut: true, //可以拖出窗外
  74. shade: false, //不显示遮罩
  75. resize: true, //拉伸
  76. title: title,
  77. content: path,
  78. shadeClose: false, // 点击遮罩关闭
  79. area: ["80%", "80%"], //大小
  80. close: (id) => {
  81. // console.log(`关闭:${id}`);
  82. const oldData = JSON.parse(sessionStorage.getItem("tagList"));
  83. // 删除本地存储中该标签的数据
  84. const newStorage = oldData.filter((item) => item.id !== id);
  85. sessionStorage.setItem("tagList", JSON.stringify(newStorage));
  86. },
  87. });
  88. item.id = thisId;
  89. sessionStorage.setItem(
  90. "tagList",
  91. JSON.stringify([...JSON.parse(sessionStorage.getItem("tagList")), item])
  92. );
  93. // }
  94. } else {
  95. const thisId = layer.open({
  96. type: "iframe", //类型
  97. move: false, //不可拖拽
  98. maxmin: true,
  99. title: title,
  100. content: path,
  101. shadeClose: false, // 点击遮罩关闭
  102. area: ["80%", "80%"], //大小
  103. close: (id) => {
  104. // console.log(`关闭:${id}`);
  105. // 删除本地存储中该标签的数据
  106. const oldData = JSON.parse(sessionStorage.getItem("tagList"));
  107. const newStorage = oldData.filter((item) => item.id !== id);
  108. sessionStorage.setItem("tagList", JSON.stringify(newStorage));
  109. },
  110. });
  111. item.id = thisId;
  112. sessionStorage.setItem("tagList", JSON.stringify([item]));
  113. }
  114. // if (!path.includes("fileEdit")) {
  115. // setInterval(() => {
  116. // const newTab = sessionStorage.getItem("newTab");
  117. // if (!newTab) {
  118. // return;
  119. // }
  120. // const tabData = JSON.parse(newTab);
  121. // openTab(tabData.name, tabData.path);
  122. // sessionStorage.removeItem("newTab");
  123. // }, 200);
  124. // }
  125. };
  126. //判断标签是否存在
  127. const hasThis = (clickRowId) => {
  128. const storage = sessionStorage.getItem("tagList");
  129. if (storage) {
  130. const oldStorage = JSON.parse(storage);
  131. // 判断是否存在相同的标签
  132. if (oldStorage.find((item) => item.path.includes(clickRowId))) {
  133. // ElMessage({ message: "该页面已经打开", type: "info" });
  134. return 1;
  135. }else{
  136. return 0;
  137. }
  138. }
  139. };
  140. const openTab = (title, path) => {
  141. const item = {
  142. title: title,
  143. path: path,
  144. };
  145. // 判断是否存在标签列表,存在则添加,不存在则创建
  146. const storage = sessionStorage.getItem("tagList");
  147. if (storage) {
  148. //如果标签数量超过11个,提示超出最大限制
  149. if (JSON.parse(storage).length >= 10) {
  150. ElMessage({ message: "标签数量超出最大限制", type: "error" });
  151. return;
  152. }
  153. const oldStorage = JSON.parse(storage);
  154. // 判断是否存在相同的标签
  155. if (oldStorage.find((item) => item.path === path)) {
  156. ElMessage({ message: "该页面已经打开", type: "info" });
  157. return;
  158. }
  159. const thisId = layer.open({
  160. type: "iframe", //类型
  161. // move: true, //拖拽
  162. maxmin: true,
  163. resize: true, //拉伸
  164. moveOut: true, //可以拖出窗外
  165. shade: false, //不显示遮罩
  166. title: title,
  167. content: path,
  168. shadeClose: false, // 点击遮罩关闭
  169. area: ["80%", "80%"], //大小
  170. close: (id) => {
  171. // console.log(`关闭:${id}`);
  172. const oldData = JSON.parse(sessionStorage.getItem("tagList"));
  173. // 删除本地存储中该标签的数据
  174. const newStorage = oldData.filter((item) => item.id !== id);
  175. sessionStorage.setItem("tagList", JSON.stringify(newStorage));
  176. },
  177. });
  178. item.id = thisId;
  179. sessionStorage.setItem(
  180. "tagList",
  181. JSON.stringify([...JSON.parse(sessionStorage.getItem("tagList")), item])
  182. );
  183. // }
  184. } else {
  185. const thisId = layer.open({
  186. type: "iframe", //类型
  187. move: false, //不可拖拽
  188. maxmin: true,
  189. title: title,
  190. content: path,
  191. shadeClose: false, // 点击遮罩关闭
  192. area: ["80%", "80%"], //大小
  193. close: (id) => {
  194. // console.log(`关闭:${id}`);
  195. // 删除本地存储中该标签的数据
  196. const oldData = JSON.parse(sessionStorage.getItem("tagList"));
  197. const newStorage = oldData.filter((item) => item.id !== id);
  198. sessionStorage.setItem("tagList", JSON.stringify(newStorage));
  199. },
  200. });
  201. item.id = thisId;
  202. sessionStorage.setItem("tagList", JSON.stringify([item]));
  203. }
  204. };
  205. // 点击logo回到主页
  206. const goIndex = () => {
  207. showSearch.value = false;
  208. };
  209. // 页面刷新后清除标签
  210. onMounted(() => {
  211. // 判断是否页面刷新 刷新就清楚存储的标签
  212. switch (performance.navigation.type) {
  213. case 0:
  214. // console.log("首次加载出来了");
  215. break;
  216. case 1:
  217. sessionStorage.removeItem("tagList");
  218. break;
  219. }
  220. if (hasRole.value) {
  221. // console.log("sidebarRouters", sidebarRouters.value);
  222. const thisItem = sidebarRouters.value.find(
  223. (item) => item.redirect == "noRedirect"
  224. ); //拿到系统管理的第一个菜单 判断依据:第一个redirect == "noRedirect"的路由
  225. const path1 = thisItem.path; //一级路由
  226. const path2 = thisItem.children[0].path; //二级路由
  227. let path3;
  228. if (thisItem.children[0].children) {
  229. path3 = thisItem.children[0].children[0].path;
  230. }
  231. systemPath.value = {
  232. label: "系统管理",
  233. // path: "/biz/dirTemplate",
  234. path: `${path1}/${path2}${path3 ? "/" + path3 : ""}`,
  235. };
  236. }
  237. // 绑定事件总线
  238. bus.on("test", (data, num) => {
  239. console.log("data", data);
  240. });
  241. window.$setOpenTab = (itemData) => {
  242. openMaxmin(itemData.name, itemData.path);
  243. };
  244. window.$hasThis = (clickRowId) => {
  245. hasThis(clickRowId);
  246. };
  247. });
  248. onUnmounted(() => {
  249. bus.off("test");
  250. clearInterval();
  251. });
  252. const changeSearch = async (val, text) => {
  253. showSearch.value = val;
  254. searchText.value = text;
  255. if (val) {
  256. if (!searchText.value) {
  257. return;
  258. }
  259. const query = {
  260. keyword: searchText.value,
  261. page: 1,
  262. size: 999,
  263. };
  264. const allQuery = {
  265. keyword: searchText.value,
  266. isAsc: "asc",
  267. orderByColumn: "createTime",
  268. pageSize: 99999,
  269. pageNum: 1,
  270. };
  271. //高级搜索
  272. searchAll(query).then((res) => {
  273. // console.log("hightData", res);
  274. if (res.data) {
  275. hightData.value = res.data;
  276. hightDataTotal.value = res.total;
  277. }
  278. });
  279. // 全域搜索
  280. flieSearch(allQuery).then((res2) => {
  281. allData.value = res2.rows;
  282. allDataTotal.value = res2.total;
  283. // console.log("allData", res2);
  284. });
  285. }
  286. };
  287. </script>
  288. <style lang="scss" scoped>
  289. @import "@/assets/styles/mixin.scss";
  290. @import "@/assets/styles/variables.module.scss";
  291. .common-layout {
  292. width: 100vw;
  293. height: 100vh;
  294. background-image: url("@/assets/images/newIndex/bgi.png");
  295. background-repeat: no-repeat;
  296. background-size: cover;
  297. }
  298. .topMenu {
  299. width: 100%;
  300. height: 80px;
  301. }
  302. .main {
  303. width: 100%;
  304. height: calc(100vh - 160px);
  305. }
  306. .footer {
  307. width: 100%;
  308. height: 80px;
  309. // border: 1px solid #000;
  310. background-color: #b5d2ea;
  311. }
  312. </style>