NewIndex.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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: "error" });
  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. const openTab = (title, path) => {
  127. const item = {
  128. title: title,
  129. path: path,
  130. };
  131. // 判断是否存在标签列表,存在则添加,不存在则创建
  132. const storage = sessionStorage.getItem("tagList");
  133. if (storage) {
  134. //如果标签数量超过11个,提示超出最大限制
  135. if (JSON.parse(storage).length >= 10) {
  136. ElMessage({ message: "标签数量超出最大限制", type: "error" });
  137. return;
  138. }
  139. const oldStorage = JSON.parse(storage);
  140. // 判断是否存在相同的标签
  141. if (oldStorage.find((item) => item.path === path)) {
  142. ElMessage({ message: "该页面已经打开", type: "error" });
  143. return;
  144. }
  145. const thisId = layer.open({
  146. type: "iframe", //类型
  147. // move: true, //拖拽
  148. maxmin: true,
  149. resize:true,//拉伸
  150. moveOut:true,//可以拖出窗外
  151. shade:false,//不显示遮罩
  152. title: title,
  153. content: path,
  154. shadeClose: false, // 点击遮罩关闭
  155. area: ["80%", "80%"], //大小
  156. close: (id) => {
  157. // console.log(`关闭:${id}`);
  158. const oldData = JSON.parse(sessionStorage.getItem("tagList"));
  159. // 删除本地存储中该标签的数据
  160. const newStorage = oldData.filter((item) => item.id !== id);
  161. sessionStorage.setItem("tagList", JSON.stringify(newStorage));
  162. },
  163. });
  164. item.id = thisId;
  165. sessionStorage.setItem(
  166. "tagList",
  167. JSON.stringify([...JSON.parse(sessionStorage.getItem("tagList")), item])
  168. );
  169. // }
  170. } else {
  171. const thisId = layer.open({
  172. type: "iframe", //类型
  173. move: false, //不可拖拽
  174. maxmin: true,
  175. title: title,
  176. content: path,
  177. shadeClose: false, // 点击遮罩关闭
  178. area: ["80%", "80%"], //大小
  179. close: (id) => {
  180. // console.log(`关闭:${id}`);
  181. // 删除本地存储中该标签的数据
  182. const oldData = JSON.parse(sessionStorage.getItem("tagList"));
  183. const newStorage = oldData.filter((item) => item.id !== id);
  184. sessionStorage.setItem("tagList", JSON.stringify(newStorage));
  185. },
  186. });
  187. item.id = thisId;
  188. sessionStorage.setItem("tagList", JSON.stringify([item]));
  189. }
  190. };
  191. // 点击logo回到主页
  192. const goIndex = () => {
  193. showSearch.value = false
  194. };
  195. // 页面刷新后清除标签
  196. onMounted(() => {
  197. // 判断是否页面刷新 刷新就清楚存储的标签
  198. switch (performance.navigation.type) {
  199. case 0:
  200. // console.log("首次加载出来了");
  201. break;
  202. case 1:
  203. sessionStorage.removeItem("tagList");
  204. break;
  205. }
  206. if (hasRole.value) {
  207. // console.log("sidebarRouters", sidebarRouters.value);
  208. const thisItem = sidebarRouters.value.find(
  209. (item) => item.redirect == "noRedirect"
  210. ); //拿到系统管理的第一个菜单 判断依据:第一个redirect == "noRedirect"的路由
  211. const path1 = thisItem.path; //一级路由
  212. const path2 = thisItem.children[0].path; //二级路由
  213. let path3;
  214. if (thisItem.children[0].children) {
  215. path3 = thisItem.children[0].children[0].path;
  216. }
  217. systemPath.value = {
  218. label: "系统管理",
  219. // path: "/biz/dirTemplate",
  220. path: `${path1}/${path2}${path3 ? "/" + path3 : ""}`,
  221. };
  222. }
  223. // 绑定事件总线
  224. bus.on("test", (data, num) => {
  225. console.log("data", data);
  226. });
  227. });
  228. onUnmounted(() => {
  229. bus.off("test");
  230. clearInterval();
  231. });
  232. const changeSearch = async (val, text) => {
  233. showSearch.value = val;
  234. searchText.value = text;
  235. if (val) {
  236. if (!searchText.value) {
  237. return;
  238. }
  239. const query = {
  240. keyword: searchText.value,
  241. page: 1,
  242. size: 999,
  243. };
  244. const allQuery = {
  245. keyword: searchText.value,
  246. isAsc: "asc",
  247. orderByColumn: "createTime",
  248. pageSize: 99999,
  249. pageNum: 1,
  250. };
  251. //高级搜索
  252. searchAll(query).then((res) => {
  253. // console.log("hightData", res);
  254. if (res.data) {
  255. hightData.value = res.data;
  256. hightDataTotal.value = res.total;
  257. }
  258. });
  259. // 全域搜索
  260. flieSearch(allQuery).then((res2) => {
  261. allData.value = res2.rows;
  262. allDataTotal.value = res2.total;
  263. // console.log("allData", res2);
  264. });
  265. }
  266. };
  267. </script>
  268. <style lang="scss" scoped>
  269. @import "@/assets/styles/mixin.scss";
  270. @import "@/assets/styles/variables.module.scss";
  271. .common-layout {
  272. width: 100vw;
  273. height: 100vh;
  274. background-image: url("@/assets/images/newIndex/bgi.png");
  275. background-repeat: no-repeat;
  276. background-size: cover;
  277. }
  278. .topMenu {
  279. width: 100%;
  280. height: 80px;
  281. }
  282. .main {
  283. width: 100%;
  284. height: calc(100vh - 160px);
  285. }
  286. .footer {
  287. width: 100%;
  288. height: 80px;
  289. // border: 1px solid #000;
  290. background-color: #b5d2ea;
  291. }
  292. </style>