indexCommon.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. <template>
  2. <div class="common-layout">
  3. <el-container>
  4. <el-header class="nav" style="position: sticky; top: 0; left: 0; width: 100%; z-index: 999">
  5. <div class="nav-top">
  6. <div>
  7. <img class="logoImg" src="@/assets/images/logos.png" /><span>聚合智慧文档管理系统</span>
  8. </div>
  9. <div class="search">
  10. <el-input v-model="searchText" maxlength="32" class="w-50 m-2" size="small"
  11. placeholder="搜索文件" clearable @keyup.enter="toSearch">
  12. </el-input>
  13. <el-icon style="position: absolute;top: 15px;left: 1200px;z-index: 1;color: white;" @click="toSearch">
  14. <Search />
  15. </el-icon>
  16. </div>
  17. <div>
  18. <el-dropdown @command="handleCommand" class="right-menu-item hover-effect" trigger="click">
  19. <div class="avatar-wrapper">
  20. <img :src="userStore.avatar
  21. ? userStore.avatar
  22. : '@/assets/images/profile.png'
  23. " class="head-img" /><span style="cursor: pointer;margin-right: 6px;">{{ userStore.name }}</span>
  24. <el-icon>
  25. <ArrowDown />
  26. </el-icon>
  27. </div>
  28. <template #dropdown>
  29. <el-dropdown-menu>
  30. <router-link to="/user/profile">
  31. <el-dropdown-item>个人中心</el-dropdown-item>
  32. </router-link>
  33. <el-dropdown-item divided command="logout">
  34. <span>退出登录</span>
  35. </el-dropdown-item>
  36. </el-dropdown-menu>
  37. </template>
  38. </el-dropdown>
  39. </div>
  40. </div>
  41. </el-header>
  42. <el-container>
  43. <el-aside width="92px" class="asides">
  44. <div class="aside-con">
  45. <router-link :to="item.path" v-for="(item, index) in menuList.data" :key="index"
  46. @click="clickPath(index, item)">
  47. <div style="position: relative" :class="$route.path == item.path
  48. ? 'acitve-img-style img-style'
  49. : 'img-style'
  50. ">
  51. <img :src="$route.path == item.path ? item.beimgs : item.imgs" />
  52. <div class="text-style" v-if="$route.path != item.path">
  53. {{ item.label }}
  54. </div>
  55. <span class="yuandian" v-if="hasNewMessage &&
  56. item.path == '/index' &&
  57. ($route.path != item.path || isSwitchFileIframe)
  58. "></span>
  59. </div>
  60. </router-link><br />
  61. </div>
  62. </el-aside>
  63. <el-main class="main">
  64. <div class="tab_box">
  65. <!-- <el-tabs
  66. v-model="editableTabsValue"
  67. @tab-change="clickTab"
  68. @tab-add="addTab"
  69. type="card"
  70. class="common-tabs"
  71. > -->
  72. <el-tabs v-model="editableTabsValue" @tab-add="addTab" type="card" class="common-tabs">
  73. <!-- <el-tab-pane label="首页" @click="clickTab('/index')"> </el-tab-pane> -->
  74. <el-tab-pane v-for="(item, index) in toRaw(editableTabs)" :key="item.path" :label="item.label"
  75. :name="item.path" :data-item="JSON.stringify(item)">
  76. <template #label>
  77. <div class="tab_pane" @click="paneClick(item)">
  78. <div class="tab_text">{{ item.label }}</div>
  79. <img v-if="item.label != '首页'" src="@/assets/images/close.png" @click="closeTab(item, index, $event)"
  80. alt="" />
  81. </div>
  82. <!-- <router-link
  83. :key="item"
  84. :data-path="item.path"
  85. :to="{
  86. path: item.path,
  87. query: { row: item.clickRowId },
  88. }"
  89. @click="paneClick(item)"
  90. class="tags-view-item"
  91. >
  92. {{ item.label }}
  93. </router-link> -->
  94. </template>
  95. </el-tab-pane>
  96. <!-- 文件的iframe -->
  97. <div v-for="item in iFrameData" :key="item.id">
  98. <el-tab-pane :label="item.name" :name="item.id" v-if="item.src">
  99. <template #label>
  100. <div class="tab_pane" @click="filePaneClick(item)">
  101. <div class="tab_text">{{ item.name }}</div>
  102. <img src="@/assets/images/close.png" @click="closeFileTab(item, index, $event)" alt="" />
  103. </div>
  104. </template>
  105. </el-tab-pane>
  106. </div>
  107. </el-tabs>
  108. </div>
  109. <div v-show="isAlive">
  110. <router-view v-slot="{ Component }" :key="$router.currentRoute.value.fullPath">
  111. <KeepAlive :exclude="['identifyFont', 'allback', 'search']">
  112. <component :is="Component" />
  113. </KeepAlive>
  114. </router-view>
  115. </div>
  116. <div v-show="!isAlive" style="width: 100%">
  117. <div v-for="item in iFrameData" :key="item.id">
  118. <div style="width: 100%" v-show="item.show">
  119. <iframe :src="item.src" frameborder="0" :id="`iframe${item.id}`" :name="`iframe${item.id}`" width="100%"
  120. height="800px" class="iframeBox" v-show="item.show"></iframe>
  121. </div>
  122. </div>
  123. </div>
  124. </el-main>
  125. </el-container>
  126. </el-container>
  127. </div>
  128. </template>
  129. <script setup>
  130. import { nextTick, onMounted, provide, ref, watchEffect, watch } from "vue";
  131. import { ElMessageBox, ElMessage } from "element-plus";
  132. import useAppStore from "@/store/modules/app";
  133. import useUserStore from "@/store/modules/user";
  134. import useSettingsStore from "@/store/modules/settings";
  135. import Cookies from "js-cookie";
  136. import chat from "@/assets/images/chat.png";
  137. import bechat from "@/assets/images/bechat.png";
  138. import zuijin from "@/assets/images/zuijin.png";
  139. import bezuijin from "@/assets/images/bezuijin.png";
  140. import colloect from "@/assets/images/colloect.png";
  141. import becolloect from "@/assets/images/becolloect.png";
  142. import system from "@/assets/images/system.png";
  143. import issystem from "@/assets/images/issystem.png";
  144. import my from "@/assets/images/my.png";
  145. import bemy from "@/assets/images/bemy.png";
  146. import bumen from "@/assets/images/bumen.png";
  147. import bebumen from "@/assets/images/bebumen.png";
  148. import common from "@/assets/images/common.png";
  149. import becommon from "@/assets/images/becommon.png";
  150. import chuanshu from "@/assets/images/chuanshu.png";
  151. import bechuanshu from "@/assets/images/bechuanshu.png";
  152. import highsearch from "@/assets/images/highsearch.png";
  153. import behighsearch from "@/assets/images/behighsearch.png";
  154. import manyBody from "@/assets/images/manyBody.png";
  155. import manyBodyFalse from "@/assets/images/manyBodyFalse.png";
  156. import { AppMain, Navbar, Settings, TagsView } from "./components";
  157. import { flieSearch } from "@/api/search/search.js";
  158. import { useRouter, useRoute } from "vue-router";
  159. import useWebsoctStore from "@/store/modules/websocket";
  160. import { toRaw } from "@vue/reactivity";
  161. import iFrame from "@/components/iFrame/index.vue";
  162. const websoctStore = useWebsoctStore();
  163. const router = useRouter(); //注册路由
  164. const route = useRoute();
  165. const appStore = useAppStore();
  166. const userStore = useUserStore();
  167. const settingsStore = useSettingsStore();
  168. const searchText = ref(""); //搜索ipt的值
  169. const selectValue = ref(1); //文档空间类型
  170. const wangzhi = import.meta.env.VITE_APP_BASE_API;
  171. const isAlive = ref(true);
  172. const toFileData = ref();
  173. const uid = useUserStore().uid;
  174. let hasNewMessage = ref(false)
  175. let isSwitchFileIframe = ref(false); //是否切换到文件预览标签
  176. const iFrameData = ref(JSON.parse(sessionStorage.getItem('fileTabData')) || [
  177. {
  178. id: 1,
  179. // src: `${window.location.origin}/fileEdit?clickRowId=113`,
  180. show: false,
  181. name: "file1",
  182. docId: ''
  183. },
  184. {
  185. id: 2,
  186. src: ``,
  187. // src: `http://192.168.1.9:81/fileEdit?clickRowId=1198`,
  188. show: false,
  189. name: "file2",
  190. docId: ''
  191. },
  192. {
  193. id: 3,
  194. src: ``,
  195. show: false,
  196. name: "",
  197. docId: ''
  198. },
  199. {
  200. id: 4,
  201. src: ``,
  202. show: false,
  203. name: "",
  204. docId: ''
  205. },
  206. {
  207. id: 5,
  208. src: ``,
  209. show: false,
  210. name: "",
  211. docId: ''
  212. },
  213. {
  214. id: 6,
  215. src: ``,
  216. show: false,
  217. name: "",
  218. docId: ''
  219. },
  220. {
  221. id: 7,
  222. src: ``,
  223. show: false,
  224. name: "",
  225. docId: ''
  226. },
  227. {
  228. id: 8,
  229. src: ``,
  230. show: false,
  231. name: "",
  232. docId: ''
  233. },
  234. {
  235. id: 9,
  236. src: ``,
  237. show: false,
  238. name: "",
  239. docId: ''
  240. },
  241. {
  242. id: 10,
  243. src: ``,
  244. show: false,
  245. name: "",
  246. docId: ''
  247. },
  248. ]);
  249. //--------tabs-----------------
  250. let tabIndex = 2;
  251. const editableTabsValue = ref(JSON.parse(sessionStorage.getItem('editableTabsValue')) || "/index");
  252. // const editableTabsValue = ref("/index");
  253. const editableTabs = ref(JSON.parse(sessionStorage.getItem('tabData')) || [{ label: '首页', path: '/reindex' }]);
  254. // const removeTab = (targetName) => {
  255. // const tabs = editableTabs.value;
  256. // let activeName = editableTabsValue.value;
  257. // if (activeName === targetName) {
  258. // tabs.forEach((tab, index) => {
  259. // if (tab.name === targetName) {
  260. // const nextTab = tabs[index + 1] || tabs[index - 1];
  261. // if (nextTab) {
  262. // activeName = nextTab.name;
  263. // }
  264. // }
  265. // });
  266. // }
  267. // editableTabsValue.value = activeName;
  268. // editableTabs.value = tabs.filter((tab) => tab.name !== targetName);
  269. // };
  270. //-------------------------
  271. function reload() {
  272. isAlive.value = false;
  273. nextTick(() => {
  274. isAlive.value = true;
  275. });
  276. }
  277. provide("reload", reload);
  278. function toggleSideBar() {
  279. appStore.toggleSideBar();
  280. }
  281. const logingName = ref("");
  282. let lisetenMessageTime = null;
  283. onMounted(() => {
  284. logingName.value = Cookies.get("username");
  285. clearInterval(lisetenMessageTime)
  286. lisetenMessageTime = setInterval(() => {
  287. //if(router.currentRoute.value.path=='/index') return;
  288. //console.log("===============window.noReadList:", localStorage.getItem("noreadlist"),'===========',isSwitchFileIframe.value)
  289. let tmplist = localStorage.getItem("noreadlist")
  290. if (tmplist == null || tmplist == '') {
  291. hasNewMessage.value = false
  292. return
  293. }
  294. tmplist = JSON.parse(tmplist);
  295. if (tmplist != null) hasNewMessage.value = true
  296. else hasNewMessage.value = false
  297. }, 1000);
  298. // console.log('onMt',editableTabsValue.value);
  299. // console.log('type',typeof editableTabsValue.value);
  300. nextTick(() => { // 要放在对响应式数据修改之后
  301. if (typeof editableTabsValue.value == 'number') {
  302. setTimeout(() => {
  303. iframeSize(editableTabsValue.value)
  304. }, 1000);
  305. }
  306. })
  307. // console.log('router',router)
  308. });
  309. watchEffect(async () => {
  310. if (router.currentRoute.value.path == '/index') return;
  311. if (websoctStore.noReadList != null) hasNewMessage.value = true
  312. else hasNewMessage.value = false
  313. // console.log("===============websoctStore.noReadList:",websoctStore.noReadList,'===========',hasNewMessage.value)
  314. });
  315. function handleCommand(command) {
  316. switch (command) {
  317. case "setLayout":
  318. setLayout();
  319. break;
  320. case "logout":
  321. logout();
  322. break;
  323. default:
  324. break;
  325. }
  326. }
  327. function logout() {
  328. ElMessageBox.confirm("确定注销并退出系统吗?", "提示", {
  329. confirmButtonText: "确定",
  330. cancelButtonText: "取消",
  331. type: "warning",
  332. })
  333. .then(() => {
  334. sessionStorage.clear()
  335. userStore.logOut().then(() => {
  336. location.href = "/index";
  337. });
  338. })
  339. .catch(() => { });
  340. }
  341. // 跳转到全文搜索
  342. const toSearch = async () => {
  343. if (!searchText.value) return;
  344. // console.log('searchText = ',searchText.value);
  345. const query = {
  346. keyword: searchText.value,
  347. isAsc: "asc",
  348. orderByColumn: "createTime",
  349. pageSize: 10,
  350. pageNum: 1,
  351. };
  352. const res = await flieSearch(query);
  353. console.log("res", res);
  354. if (res) {
  355. const itemData = {
  356. name: '全局搜索',
  357. path: 'search',
  358. clickRowId: {
  359. searchData: res,
  360. searchText: searchText.value,
  361. }
  362. }
  363. addFolderAdd(itemData)
  364. // console.log("res", res);
  365. // console.log("router", route.path);
  366. // if (route.path != "/search") {
  367. // let listArr = JSON.stringify(res);
  368. // router.push({
  369. // name: 'search',
  370. // params: {
  371. // listArr: listArr,
  372. // searchText: searchText.value
  373. // }
  374. // });
  375. // } else {
  376. // router.replace({
  377. // path: "/allback",
  378. // query: {
  379. // searchData: JSON.stringify(res),
  380. // searchText: searchText.value,
  381. // },
  382. // });
  383. // }
  384. }
  385. };
  386. const emits = defineEmits(["setLayout"]);
  387. function setLayout() {
  388. emits("setLayout");
  389. }
  390. const clickId = ref("");
  391. const menuList = reactive({
  392. data: [
  393. {
  394. label: "会话消息",
  395. path: "/index",
  396. imgs: chat,
  397. beimgs: bechat,
  398. },
  399. // {
  400. // label: "接口",
  401. // path: "/swagger",
  402. // imgs: chat,
  403. // beimgs: bechat,
  404. // disabled:true
  405. // },
  406. {
  407. label: "最近文件",
  408. path: "/recent",
  409. imgs: zuijin,
  410. beimgs: bezuijin,
  411. },
  412. {
  413. label: "收藏文件",
  414. path: "/collect",
  415. imgs: colloect,
  416. beimgs: becolloect,
  417. },
  418. {
  419. label: "我的文件",
  420. path: "/myfile",
  421. imgs: my,
  422. beimgs: bemy,
  423. },
  424. {
  425. label: "部门文件",
  426. path: "/department",
  427. imgs: bumen,
  428. beimgs: bebumen,
  429. },
  430. {
  431. label: "公共文件",
  432. path: "/publicment",
  433. imgs: common,
  434. beimgs: becommon,
  435. },
  436. {
  437. label: "高级搜索",
  438. path: "/highsearch",
  439. imgs: highsearch,
  440. beimgs: behighsearch,
  441. },
  442. // {
  443. // label: "传输列表",
  444. // path: "/transFile",
  445. // imgs: chuanshu,
  446. // beimgs: bechuanshu,
  447. // },
  448. // {
  449. // label: "系统管理",
  450. // path: "/admin",
  451. // imgs: system,
  452. // beimgs: issystem,
  453. // },
  454. {
  455. label: "我的协作",
  456. path: "/myjoin",
  457. imgs: manyBody,
  458. beimgs: manyBodyFalse,
  459. },
  460. ],
  461. });
  462. const roles = useUserStore().roles;
  463. const permissionRoles = ['admin', 'dept', 'system', 'audit']
  464. const super_admin = "admin";
  465. const hasRole = roles.some(role => {
  466. return super_admin === role || permissionRoles.includes(role)
  467. })
  468. if (hasRole) {
  469. menuList.data.push(
  470. {
  471. label: "系统管理",
  472. path: "/admin",
  473. imgs: system,
  474. beimgs: issystem,
  475. }
  476. );
  477. }
  478. const clickPath = (index, items) => {
  479. items = toRaw(items);
  480. localStorage.setItem("inChat", items.path == "/index" ? 1 : 0)
  481. // toFileData.value = null
  482. console.log("clickPathitems", items);
  483. // editableTabs.value = arr;
  484. isSwitchFileIframe.value = false
  485. const arr = toRaw(editableTabs.value);
  486. if (!arr.some((item) => item.label == items.label)) {
  487. editableTabs.value.push({
  488. label: items.label,
  489. path: items.path,
  490. });
  491. //需要jSON去转 否则页面无变化 离谱得很
  492. editableTabs.value = JSON.parse(JSON.stringify(editableTabs.value));
  493. } else {
  494. toFileData.value = null;
  495. clickTab(items.path);
  496. }
  497. editableTabsValue.value = items.path;
  498. isAlive.value = true;
  499. // console.log("editableTabs", editableTabs.value);
  500. };
  501. const clickTab = (item) => {
  502. let url = toRaw(item)
  503. setTimeout(() => {
  504. console.log("toFileData.value", toFileData.value);
  505. if (toFileData.value) {
  506. localStorage.setItem("inChat", 0)
  507. // 去全文搜索单独判断
  508. if (toFileData.value.name == "全局搜索" || toFileData.value.label == "全局搜索") {
  509. // console.log("clickRowId.value", JSON.stringify(toRaw(toFileData.value).clickRowId));
  510. editableTabsValue.value = toFileData.value.path
  511. isAlive.value = true
  512. console.log('route', route.path);
  513. // 如果当前已经在search就跳到中转页面
  514. if (route.path == "/search") {
  515. router.push({
  516. path: '/allback',
  517. query: {
  518. // row: JSON.stringify(toRaw(toFileData.value.clickRowId)),
  519. clickRowId: JSON.stringify(toRaw(toFileData.value).clickRowId),
  520. },
  521. });
  522. } else {
  523. // 否则去search
  524. router.push({
  525. name: toFileData.value.path,
  526. state: {
  527. // row: JSON.stringify(toRaw(toFileData.value.clickRowId)),
  528. clickRowId: JSON.stringify(toRaw(toFileData.value).clickRowId),
  529. },
  530. });
  531. }
  532. return
  533. }
  534. // 去文字识别单独判断
  535. if (toFileData.value.name == "文字识别" || toFileData.value.label == "文字识别") {
  536. // console.log("clickRowId.value", JSON.stringify(toRaw(toFileData.value).clickRowId));
  537. editableTabsValue.value = toFileData.value.path
  538. isAlive.value = true
  539. console.log('route', route.path);
  540. router.push({
  541. name: toFileData.value.path,
  542. state: {
  543. // row: JSON.stringify(toRaw(toFileData.value.clickRowId)),
  544. clickRowId: JSON.stringify(toRaw(toFileData.value).clickRowId),
  545. },
  546. });
  547. return
  548. }
  549. editableTabsValue.value = toFileData.value.path
  550. router.push({
  551. path: toFileData.value.path,
  552. query: {
  553. // row: JSON.stringify(toRaw(toFileData.value.clickRowId)),
  554. clickRowId: toRaw(toFileData.value.clickRowId).dirId,
  555. },
  556. });
  557. return;
  558. }
  559. localStorage.setItem("inChat", url == "/index" ? 1 : 0)
  560. let regExp = new RegExp(/^\//);
  561. if (!regExp.test(url)) {
  562. const data = JSON.parse(url);
  563. console.log("data", data);
  564. router.push({
  565. // path: "/fileEdit" + data.docId,
  566. path: "/fileEdit",
  567. query: {
  568. clickRowId: data.docId,
  569. // row:JSON.stringify(toFileData.value)
  570. // copyRow: JSON.stringify(data),
  571. },
  572. });
  573. } else {
  574. editableTabsValue.value = url
  575. router.push({
  576. path: item + '?dirId=' + item,
  577. });
  578. }
  579. }, 0);
  580. };
  581. const paneClick = (item) => {
  582. // 可以拿到当前的标签对象
  583. console.log(item, 'pane');
  584. isAlive.value = true;
  585. isSwitchFileIframe.value = false
  586. // console.log("paneItem", item);
  587. if (item.clickRowId) {
  588. // 判断是菜单还是目录
  589. toFileData.value = item;
  590. } else {
  591. toFileData.value = null;
  592. }
  593. clickTab(item.path);
  594. };
  595. // 点击文件标签
  596. const filePaneClick = (item) => {
  597. localStorage.setItem("inChat", 0)
  598. console.log("filePaneClickitem", item);
  599. isSwitchFileIframe.value = true
  600. const row = toRaw(item);
  601. const arr = iFrameData.value.map((par) => {
  602. if (par.id === row.id) {
  603. // editableTabsValue.value = row.id
  604. par.show = true;
  605. // document.getElementById('iframe'+par.id).window.document.iframe[0]
  606. const outIframe = document.getElementById("iframe" + par.id);
  607. const inIframe =
  608. outIframe.contentDocument.getElementsByTagName("iframe")[0];
  609. setTimeout(() => {
  610. // console.log('outIframe',outIframe.parentElement);
  611. console.error(outIframe.parentElement);
  612. inIframe.style.height = outIframe.style.height =
  613. outIframe.parentElement.offsetHeight + "px";
  614. inIframe.style.width = outIframe.style.width =
  615. outIframe.parentElement.offsetWidth + "px";
  616. // console.log('dom',outIframe.parentElement.offsetWidth);
  617. // console.log('inIframe',inIframe);
  618. }, 500);
  619. } else {
  620. par.show = false;
  621. }
  622. return toRaw(par);
  623. });
  624. iFrameData.value = arr;
  625. // console.log("Clicknewfilearr", iFrameData.value);
  626. isAlive.value = false;
  627. // console.log("editableTabsValue", editableTabsValue.value);
  628. };
  629. // 创建文件的标签
  630. const addFileTab = (data, bool,copy) => {
  631. // console.log("addFileTab", data);
  632. const thisData = JSON.parse(JSON.stringify(toRaw(data)));
  633. const oldIFrameData = iFrameData.value;
  634. const canAdd = oldIFrameData.some((par) => par.src == ""); //是否达到上限
  635. if (!canAdd) return ElMessage.error("已到最大数量,请先关闭其他文件!");
  636. const hasThis = oldIFrameData.find((par) => par.docId == data.docId);//是否已存在
  637. if (hasThis) {
  638. // 已存在打开当前的并且改变编辑状态
  639. const thisPane = toRaw(hasThis)
  640. // 如果编辑状态改变了 先删除旧的 再新建
  641. if(thisPane.src != `${window.location.origin}/fileEdit?clickRowId=${thisData.docId}&canEdit=${bool}&canCopy=${copy}` ){
  642. // console.log('buyiyang',`${window.location.origin}/fileEdit?clickRowId=${thisData.docId}&canEdit=${bool}`);
  643. const arr = oldIFrameData.map((par) => {
  644. if (par.id === thisPane.id) {
  645. par.src = "";
  646. par.show = false;
  647. par.name = "";
  648. par.docId = ''
  649. }
  650. return toRaw(par);
  651. });
  652. iFrameData.value = arr.map((par) => {
  653. if (!par.src) {
  654. if (thisData.docId) {
  655. // par.src = `${window.location.origin}/fileEdit?clickRowId=${thisData.docId}`;
  656. par.src = `${window.location.origin}/fileEdit?clickRowId=${thisData.docId}&canEdit=${bool}&canCopy=${copy}`;
  657. par.name = data.fileName;
  658. par.docId = data.docId
  659. par.show = true
  660. thisData.docId = "";
  661. editableTabsValue.value = par.id// 新建时标签跳转
  662. setTimeout(() => {
  663. iframeSize(par.id)
  664. }, 1000);
  665. }
  666. } else {
  667. par.show = false
  668. }
  669. return toRaw(par);
  670. });
  671. isAlive.value = false;
  672. return
  673. }
  674. // console.log('hasThis',thisPane);
  675. const arr = oldIFrameData.map((par) => {
  676. if (par.id == thisPane.id) {
  677. `${window.location.origin}/fileEdit?clickRowId=${thisData.docId}&canEdit=${bool}&canCopy=${copy}`
  678. par.show = true
  679. editableTabsValue.value = par.id// 标签跳转
  680. setTimeout(() => {
  681. iframeSize(par.id)
  682. }, 1000);
  683. } else {
  684. par.show = false
  685. }
  686. return toRaw(par);
  687. });
  688. iFrameData.value = arr;
  689. isAlive.value = false;
  690. return
  691. }
  692. // 新增标签
  693. const arr = oldIFrameData.map((par) => {
  694. if (!par.src) {
  695. if (thisData.docId) {
  696. // par.src = `${window.location.origin}/fileEdit?clickRowId=${thisData.docId}`;
  697. par.src = `${window.location.origin}/fileEdit?clickRowId=${thisData.docId}&canEdit=${bool}&canCopy=${copy}`;
  698. par.name = data.fileName;
  699. par.docId = data.docId
  700. par.show = true
  701. thisData.docId = "";
  702. editableTabsValue.value = par.id// 新建时标签跳转
  703. setTimeout(() => {
  704. iframeSize(par.id)
  705. }, 1000);
  706. }
  707. } else {
  708. par.show = false
  709. }
  710. return toRaw(par);
  711. });
  712. iFrameData.value = arr;
  713. isAlive.value = false;
  714. // console.log("addFileTab", arr);
  715. };
  716. //创建tab标签事件
  717. const addTab = (data) => {
  718. // console.log("addTab", data);
  719. const arr = toRaw(editableTabs.value);
  720. if (!arr.some((item) => item.label == data.fileName)) {
  721. // editableTabs.value.push({
  722. // label: data.fileName,
  723. // path: JSON.stringify(data),
  724. // });
  725. editableTabs.value.push({
  726. label: data.fileName,
  727. path: JSON.stringify(data),
  728. });
  729. //需要jSON去转 否则页面无变化 离谱得很
  730. editableTabs.value = JSON.parse(JSON.stringify(editableTabs.value));
  731. // editableTabsValue.value = data.path;
  732. }
  733. };
  734. const addFolderAdd = (data) => {
  735. const arr = toRaw(editableTabs.value);
  736. if (!arr.some((item) => item.label == data.clickRowId.dirName || item.label == data.name)) {
  737. editableTabs.value.push({
  738. label: data.name,
  739. path: data.path,
  740. clickRowId: data.clickRowId,
  741. });
  742. //需要jSON去转 否则页面无变化 离谱得很
  743. editableTabs.value = JSON.parse(JSON.stringify(editableTabs.value));
  744. }
  745. editableTabsValue.value = data.path
  746. toFileData.value = data
  747. clickTab(data)
  748. // console.log("editableTabs", toRaw(editableTabs.value));
  749. };
  750. provide("addTab", addTab);
  751. provide("addFolderAdd", addFolderAdd);
  752. provide("addFileTab", addFileTab);
  753. // TODO 删除tab事件
  754. const closeTab = (item, index, e) => {
  755. e.preventDefault();
  756. e.stopPropagation();
  757. editableTabs.value.splice(index, 1);
  758. editableTabs.value = JSON.parse(JSON.stringify(editableTabs.value));
  759. const nextTab = editableTabs.value[index - 1];
  760. // console.log('nextTab',toRaw(nextTab));
  761. // console.log('item',item);
  762. // console.log('editableTabsValue',editableTabsValue.value);
  763. if (editableTabsValue.value == item.path) {
  764. paneClick(toRaw(nextTab));
  765. }
  766. // console.log("item", item);
  767. // console.log("index", index);
  768. // console.log("e", e);
  769. };
  770. // TODO 删除tab事件
  771. const closeFileTab = (item, index, e) => {
  772. e.preventDefault();
  773. e.stopPropagation();
  774. const data = toRaw(item);
  775. let arr = iFrameData.value.map((par) => {
  776. if (par.id === data.id) {
  777. par.src = "";
  778. par.show = false;
  779. par.name = "";
  780. par.docId = ''
  781. }
  782. return toRaw(par);
  783. });
  784. if (data.id == editableTabsValue.value) {
  785. let isLeft = true
  786. //如果不是第一个就左移
  787. for (let thisId = data.id; thisId > 0; thisId--) {
  788. // console.log(arr[thisId - 1].id, arr[thisId - 1].src);
  789. if (arr[thisId - 1].src) {
  790. arr[thisId - 1].show = true
  791. isLeft = false
  792. editableTabsValue.value = arr[thisId - 1].id
  793. return
  794. }
  795. }
  796. // 如果是第一个就跳到文件夹标签右一
  797. if (isLeft) {
  798. const num = toRaw(editableTabs.value).length - 1
  799. const nextTab = editableTabs.value[num]
  800. paneClick(toRaw(nextTab));
  801. // console.log('left', nextTab);
  802. }
  803. // isAlive.value = true;
  804. }
  805. iFrameData.value = arr;
  806. // console.log("index", index);
  807. // console.log("iFrameData", iFrameData.value);
  808. };
  809. // 控制iframe大小
  810. const iframeSize = (id) => {
  811. const outIframe = document.getElementById("iframe" + id);
  812. const inIframe =
  813. outIframe.contentDocument.getElementsByTagName("iframe")[0];
  814. // console.log('outIframe', outIframe.parentElement);
  815. // console.error(outIframe.parentElement);
  816. inIframe.style.height = outIframe.style.height =
  817. outIframe.parentElement.offsetHeight + "px";
  818. inIframe.style.width = outIframe.style.width =
  819. outIframe.parentElement.offsetWidth + "px";
  820. // console.log('dom',outIframe.parentElement.offsetWidth);
  821. // console.log('inIframe',inIframe);
  822. }
  823. // 监听和保存标签信息
  824. const setTabLocal = (data) => {
  825. // console.log('setTabLocal',data);
  826. sessionStorage.setItem('tabData', JSON.stringify(data))
  827. }
  828. const setFileTabLocal = (data) => {
  829. console.log('setFileTabLocal', data);
  830. isSwitchFileIframe.value = true
  831. // console.log('setFileTabLocal',data);
  832. sessionStorage.setItem('fileTabData', JSON.stringify(data))
  833. }
  834. const setEditableTabsValue = (data) => {
  835. // console.log('setEditableTabsValue',data);
  836. sessionStorage.setItem('editableTabsValue', JSON.stringify(data))
  837. }
  838. watch(() => iFrameData.value, (newValue, oldValue) => {
  839. // console.log('iFrameData 发生改变了', newValue, oldValue);
  840. setFileTabLocal(toRaw(toRaw(newValue)))
  841. }, {
  842. immediate: true,
  843. deep: true
  844. });
  845. watch(() => editableTabs.value, (newValue, oldValue) => {
  846. // console.log('editableTabs 发生改变了', newValue, oldValue);
  847. setTabLocal(toRaw(newValue))
  848. }, {
  849. immediate: true,
  850. deep: true
  851. });
  852. watch(() => editableTabsValue.value, (newValue, oldValue) => {
  853. // console.log('editableTabsValue 发生改变了', newValue, oldValue);
  854. setEditableTabsValue(toRaw(newValue))
  855. let regExp = new RegExp(/^\//);
  856. if (!regExp.test(editableTabsValue.value)) {
  857. isAlive.value = false;
  858. }
  859. }, {
  860. immediate: true,
  861. deep: true
  862. });
  863. </script>
  864. <style lang="scss" scoped>
  865. @import "@/assets/styles/mixin.scss";
  866. @import "@/assets/styles/variables.module.scss";
  867. //整体布局css
  868. .common-layout,
  869. .el-container {
  870. height: 94vh;
  871. }
  872. :deep .el-main {
  873. --el-main-padding: 8px !important;
  874. }
  875. .nav {
  876. background: #06286c;
  877. height: 48px;
  878. .nav-top {
  879. width: 98%;
  880. display: flex;
  881. justify-content: space-between;
  882. &>div:first-child {
  883. font-family: "Inter-SemiBold";
  884. }
  885. &>div:first-child,
  886. &>div:last-child {
  887. display: flex;
  888. align-items: center;
  889. color: #fff;
  890. &>img {
  891. width: 48px;
  892. height: 48px;
  893. }
  894. }
  895. .logoImg {
  896. width: 150px !important;
  897. height: 100%;
  898. margin-right: 10px;
  899. }
  900. }
  901. .head-img {
  902. border-radius: 12px;
  903. width: 24px;
  904. height: 24px;
  905. margin-right: 10px;
  906. }
  907. .avatar-wrapper {
  908. color: #fff;
  909. display: flex;
  910. align-items: center;
  911. }
  912. .search {
  913. .w-50,
  914. :deep .el-input {
  915. width: 400px;
  916. height: 32px;
  917. border-radius: 4px;
  918. margin-top: 8px;
  919. background: #6f85b5 !important;
  920. --el-input-border-color: #6f85b5;
  921. }
  922. ::v-deep .el-input__inner {
  923. color: #fff !important;
  924. }
  925. }
  926. :deep .el-input__wrapper {
  927. background: #1f3f7e !important;
  928. }
  929. }
  930. .asides {
  931. padding: 8px 10px !important;
  932. font-size: 14px;
  933. color: #000;
  934. background: #fff;
  935. }
  936. .main {
  937. background: #c7cbd8;
  938. }
  939. // tabs标签
  940. .tab_box {
  941. width: 100%;
  942. height: 32px;
  943. border-radius: 4px 4px 4px 4px;
  944. background-color: #fff;
  945. margin-bottom: 8px;
  946. .common-tabs {
  947. height: 32px;
  948. // display: flex;
  949. // align-items: center;
  950. }
  951. .tab_pane {
  952. display: flex;
  953. align-items: center;
  954. justify-content: space-between;
  955. img {
  956. margin-left: 8px;
  957. width: 10px;
  958. height: 10px;
  959. }
  960. }
  961. }
  962. :deep(.common-tabs .el-tabs__item) {
  963. height: 24px !important;
  964. padding: 0px 8px !important;
  965. margin-top: 4px !important;
  966. margin-left: 4px !important;
  967. border: 1px solid #c1cce3 !important;
  968. color: #505870 !important;
  969. font-size: 12px !important;
  970. line-height: 24px;
  971. font-weight: 400 !important;
  972. }
  973. // tag选中颜色
  974. :deep(.common-tabs .el-tabs__item.is-active) {
  975. color: #fff !important;
  976. font-weight: normal;
  977. background-color: #6f85b5;
  978. }
  979. //侧边栏css
  980. .acitve-img-style {
  981. background-color: #f5f7f9;
  982. border-radius: 4px;
  983. }
  984. .img-style {
  985. width: 72px;
  986. height: 72px;
  987. display: flex;
  988. margin-bottom: 8px;
  989. flex-direction: column;
  990. align-items: center;
  991. justify-content: center;
  992. &>img {
  993. width: 40px;
  994. height: 40px;
  995. }
  996. }
  997. .text-style {
  998. text-align: center;
  999. color: #000;
  1000. }
  1001. </style>
  1002. <style lang="scss" scoped>
  1003. .el-popper.is-light.type_popper {
  1004. background-color: #1f3f7e !important;
  1005. border-radius: 4px 4px 4px 4px !important;
  1006. border: none !important;
  1007. // padding: 0 16px !important;
  1008. // box-sizing: border-box !important;
  1009. }
  1010. .el-popper__arrow::before {
  1011. content: none;
  1012. }
  1013. //鼠标移动上去的选中色
  1014. .type_popper {
  1015. .el-select-dropdown__item.hover,
  1016. .el-select-dropdown__item:hover {
  1017. background: #6f85b5 !important;
  1018. }
  1019. //下拉框的文本颜色
  1020. .el-select-dropdown__item {
  1021. color: #a4b0d8 !important;
  1022. }
  1023. //选中之后的颜色
  1024. .el-select-dropdown__item.selected {
  1025. background: #6f85b5 !important;
  1026. color: #fff !important;
  1027. }
  1028. }
  1029. .yuandian {
  1030. width: 8px;
  1031. height: 8px;
  1032. position: absolute;
  1033. right: 8px;
  1034. top: 6px;
  1035. background: #fa5151;
  1036. border-radius: 4px;
  1037. }
  1038. ::v-deep .qualityManual-container-office {
  1039. width: 1000px !important;
  1040. height: 1000px !important;
  1041. iframe {
  1042. width: 1000px !important;
  1043. height: 1000px !important;
  1044. }
  1045. }
  1046. :deep(.el-tabs--card>.el-tabs__header) {
  1047. border-bottom: none !important;
  1048. }
  1049. </style>