knowledge-left.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <template>
  2. <div style="position: relative">
  3. <div class="left-containe hiddenScroll" :class="[notFixed?'':'notFixed']">
  4. <div class="catalogue">
  5. <template v-if="!search_show">
  6. <span>目录</span>
  7. <div>
  8. <span><i class="add-document el-icon-search" style="cursor: pointer;margin-right: 10px;" @click.stop="showSearch"></i></span>
  9. <span><i class="add-document el-icon-s-unfold" style="cursor: pointer;margin-right: 10px;" @click.stop="foldArticle()"></i></span>
  10. <span v-if="isMember || isManager"><i class="add-document el-icon-plus" style="cursor: pointer;" @click.stop="newArticle"></i></span>
  11. </div>
  12. </template>
  13. <template v-if="search_show">
  14. <el-input ref="searchInput" v-model="inputKeyword" :clearable="true" placeholder="搜索文章" @blur="blurSearch" @keyup.enter.native="toSearchArticle" size="small">
  15. </el-input>
  16. </template>
  17. </div>
  18. <div class="catalogue-tree">
  19. <el-tree ref=slotTree
  20. highlight-current
  21. draggable
  22. :filter-node-method="filterNode"
  23. :node-key="NODE_KEY"
  24. :data="catalogueTree"
  25. :props="catalogueProps"
  26. :default-expand-all="expand_all"
  27. :expand-on-click-node="false"
  28. :current-node-key="article_id"
  29. :allow-drag="allowDrag"
  30. :allow-drop="allowDrop"
  31. @node-drop="handledropNode"
  32. @node-click="handleNodeClick"
  33. >
  34. <div class="catalogue-tree-node" slot-scope="{ node, data }">
  35. <el-input
  36. v-if="node.isEdit"
  37. v-model="data.article_name"
  38. autofocus
  39. size="mini"
  40. :ref="'slotTreeInput'+data[NODE_KEY]"
  41. @blur.stop="handleBlur(node, data)"
  42. @keyup.enter.native="handleInput(node, data)"
  43. ></el-input>
  44. <div v-else class="node-containe">
  45. <span class="node-text text-over">
  46. {{data.article_name}}
  47. </span>
  48. <div class="option-node" v-if="isMember || isManager">
  49. <i class="add-document el-icon-plus" @click.stop="handleEdit(node, data)"></i>
  50. <el-popover
  51. :value="node.isShowOptPop"
  52. trigger="click"
  53. placement="bottom"
  54. width="200"
  55. >
  56. <!--<div style="cursor: pointer;margin-bottom:10px" @click.stop="handleEdit(node, data)">新建</div>-->
  57. <div style="cursor: pointer;margin-bottom:10px" @click.stop="handleRename(node, data)">重命名</div>
  58. <div style="cursor: pointer;margin-bottom:10px" @click.stop="showDialog(node, data)">移动到</div>
  59. <div style="cursor: pointer;margin-bottom:10px" @click.stop="toArticleEditor(node, data)">编辑</div>
  60. <div style="cursor: pointer;margin-bottom:10px" v-if="isManager" @click="handleDelete(node, data)">
  61. 删除
  62. </div>
  63. <i slot="reference" class="set-node el-icon-setting" @click.stop></i>
  64. </el-popover>
  65. </div>
  66. </div>
  67. </div>
  68. </el-tree>
  69. </div>
  70. </div>
  71. <el-dialog title="移动到..."
  72. :visible.sync="dialogTableVisible"
  73. :lock-scroll="true"
  74. >
  75. <div class="scroll-box">
  76. <div>
  77. <el-select v-model="select_base" @change="changeBase" placeholder="请选择知识库">
  78. <el-option
  79. v-for="item in base_options"
  80. :key="item.id"
  81. :label="item.name"
  82. :value="item.id">
  83. </el-option>
  84. </el-select>
  85. <el-input style="width: 350px;" v-model="article_sort" placeholder="请输入文章排序(数字越大排序越前,默认0)">
  86. </el-input>
  87. </div>
  88. <el-tree
  89. highlight-current
  90. :node-key="NODE_KEY"
  91. :data="selectTree"
  92. :props="catalogueProps"
  93. :default-expand-all="true"
  94. :expand-on-click-node="false"
  95. :current-node-key="article_id"
  96. @node-click="clickDialogNode"
  97. >
  98. <div class="catalogue-tree-node" slot-scope="{ node, data }">
  99. <div class="node-containe">
  100. <span class="node-text text-over">
  101. {{node.label}}
  102. </span>
  103. <div class="hidden radio-box">
  104. <span style="color:#bfbfbf">移动为</span>
  105. <el-radio-group v-model="radio">
  106. <el-radio :label="0">同级</el-radio>
  107. <el-radio :label="1">子级</el-radio>
  108. </el-radio-group>
  109. </div>
  110. <div class="hidden selector-tree-placeholder"
  111. :style="{left: radio==1?'25px':'',width: radio==1?'96%':''}"></div>
  112. </div>
  113. </div>
  114. </el-tree>
  115. </div>
  116. <span slot="footer" class="dialog-footer">
  117. <el-button @click="dialogTableVisible = false">取 消</el-button>
  118. <el-button type="primary" @click="confirmMove">确 定</el-button>
  119. </span>
  120. </el-dialog>
  121. </div>
  122. </template>
  123. <script>
  124. import {mapState} from "vuex";
  125. export default {
  126. data() {
  127. return {
  128. expand_all: false,
  129. search_show: false,
  130. inputKeyword: '',
  131. article_id: '', // 文章id
  132. article_sort: "", //文章排序
  133. // base_id: '', // 知识库id
  134. show_type: 1, // 1 PC端 2 移动端
  135. isManager: false,
  136. isMember: false,
  137. // 目录
  138. catalogueTree: [],
  139. catalogueProps: {
  140. label: "article_name",
  141. children: "child",
  142. },
  143. parentData: "",
  144. // 树节点参数
  145. NODE_KEY: 'id',
  146. MAX_LEVEL: 4,
  147. moveNode: '', // 需要弹框移动的节点
  148. notFixed: true,
  149. dialogTableVisible: false,
  150. radio: 0,
  151. selectTree: [],
  152. base_options: [],
  153. select_base: ''
  154. };
  155. },
  156. watch: {
  157. base_id() {
  158. this.select_base = Number(this.base_id);
  159. this.getTreeData();
  160. },
  161. },
  162. computed: {
  163. ...mapState(["basic_info", "basicSet"]),
  164. base_id() {
  165. return this.$route.query.base_id;
  166. },
  167. },
  168. mounted() {
  169. this.select_base = Number(this.base_id);
  170. this.getTreeData();
  171. //监听滚动条
  172. // window.addEventListener('scroll', this.handleScroll);
  173. },
  174. destroyed() {
  175. // window.removeEventListener('scroll', this.handleScroll);
  176. },
  177. methods: {
  178. showSearch() {
  179. this.search_show = true;
  180. setTimeout(()=>{
  181. this.$refs.searchInput.focus();
  182. },300);
  183. },
  184. filterNode(value, data) {
  185. if (!value) return true
  186. return data.article_name.indexOf(value) !== -1
  187. },
  188. blurSearch() {
  189. this.search_show = false;
  190. if(!this.inputKeyword.trim()) {
  191. this.$refs.slotTree.filter('')
  192. }
  193. },
  194. toSearchArticle() {
  195. this.$refs.slotTree.filter(this.inputKeyword.trim())
  196. },
  197. foldArticle(id) {
  198. let nodes= this.$refs.slotTree.store.nodesMap;
  199. if(id) {
  200. // 通过循环展开树形
  201. for(let i in nodes){
  202. if(nodes[i].data.id == id) {
  203. nodes[i].expanded = true;
  204. if(nodes[i].data.parent_id != 0) {
  205. this.foldArticle(nodes[i].data.parent_id)
  206. }
  207. }
  208. }
  209. }else {
  210. this.expand_all = !this.expand_all;
  211. for(let i in nodes){
  212. nodes[i].expanded = this.expand_all;
  213. }
  214. }
  215. },
  216. newArticle() {
  217. this.$router.push(this.fun.getUrl("knowledge-knowledge_editor", {}, {base_id: this.base_id, articleId: -1}));
  218. },
  219. // 目录树结构
  220. getTreeData(base_id = this.base_id, type) {
  221. this.fun.$get("plugin.message-base.frontend.article.baseArticle", {base_id: base_id})
  222. .then((response) => {
  223. // console.log("知识库结构列表:::", response);
  224. if (response.result !== 1) {
  225. console.log(response.msg);
  226. return;
  227. }
  228. this.isMember = response.data.is_member;
  229. this.isManager = response.data.is_manager;
  230. if (response.data.article_list.length <= 0) {
  231. this.$store.commit("setBreadcrumbs", {
  232. base: {
  233. id: response.data.base.id,
  234. name: response.data.base.name
  235. },
  236. });
  237. this.$store.commit("setBaseAuths", {
  238. isMember: this.isMember,
  239. isManager: this.isManager,
  240. isNoList: true,
  241. });
  242. return;
  243. }
  244. this.$store.commit("setBaseAuths", {
  245. isMember: this.isMember,
  246. isManager: this.isManager,
  247. });
  248. this.selectTree = response.data.article_list;
  249. if(type !== 'change') {
  250. this.$store.commit("setArticleTree", response.data.article_list);
  251. this.catalogueTree = response.data.article_list;
  252. }
  253. if(type !== 'move') {
  254. if (!this.$route.params.articleId || this.$route.params.articleId == -1) {
  255. this.article_id = this.catalogueTree[0].id;
  256. // this.getArticleDetail(this.article_id);
  257. } else {
  258. this.article_id = this.$route.params.articleId;
  259. // this.getArticleDetail(this.article_id);
  260. }
  261. }
  262. this.$nextTick(() => {
  263. //默认选中
  264. if (this.$refs.slotTree) this.$refs.slotTree.setCurrentKey(this.article_id);
  265. this.foldArticle(this.$route.params.articleId);
  266. })
  267. })
  268. },
  269. // 是否具有拖拽权限
  270. allowDrag() {
  271. return this.isManager || this.isMember;
  272. },
  273. // 放置校验
  274. allowDrop(draggingNode, dropNode, type) {
  275. // if (draggingNode.data.parent_id === dropNode.data.parent_id) {
  276. // return;
  277. // } else {
  278. return true;
  279. // }
  280. },
  281. // 点击
  282. handleNodeClick(e) {
  283. if(this.article_id!=e.id) {
  284. if(e.child && e.child.length > 0) {
  285. this.foldArticle(e.id);
  286. }
  287. this.article_id = e.id;
  288. this.$store.commit('setKnowledgeLoading', true);
  289. this.$router.push(this.fun.getUrl("knowledge-knowledge_detail-articleId", {articleId: this.article_id}, {base_id: this.base_id}));
  290. }
  291. },
  292. // 修改
  293. handleInput(_node, _data) {
  294. if (!this.isMember && !this.isManager) {
  295. this.$message.error("暂无权限操作");
  296. return;
  297. }
  298. if (_node.isEdit) {
  299. this.$set(_node, 'isEdit', false)
  300. }
  301. if (_data.article_name === '') {
  302. this.$set(_data, "article_name", "新增文章")
  303. }
  304. },
  305. // 失去焦点
  306. handleBlur(_node, _data) {
  307. // 新增-请求
  308. // let addNodeRequset = () => {
  309. // this.fun.$get("plugin.message-base.frontend.article.changeArticle", {
  310. // base_id: this.base_id,
  311. // parent_id: _data.parent_id,
  312. // article_name: _data.article_name,
  313. // article: '',
  314. // })
  315. // .then((response) => {
  316. // if (response.result !== 1) {
  317. // this.$refs.slotTree.remove(_data);
  318. // this.$message.error(response.msg);
  319. // return;
  320. // }
  321. // this.$set(_data, 'id', response.data.id);
  322. // this.$message.success(response.msg);
  323. // });
  324. // };
  325. // 修改-请求
  326. let editNodeRequest = () => {
  327. this.fun.$get("plugin.message-base.frontend.article.changeArticle", {
  328. article_id: _data.id,
  329. article_name: _data.article_name
  330. })
  331. .then((response) => {
  332. if (response.result !== 1) {
  333. this.$message.error(response.msg);
  334. }else {
  335. if(this.article_id == _data.id) {
  336. location.reload();
  337. }
  338. }
  339. });
  340. }
  341. // this.isCreate ? addNodeRequset() : editNodeRequest();
  342. editNodeRequest()
  343. this.$set(_node, 'isEdit', false);
  344. },
  345. // 新增
  346. handleEdit(_node, _data) {
  347. if (!this.isMember && !this.isManager) {
  348. this.$message.error("暂无权限操作");
  349. return;
  350. }
  351. if (_node.level >= this.MAX_LEVEL) {
  352. this.$message.warning("当前已达到" + this.MAX_LEVEL + "级,无法新增!")
  353. return;
  354. }
  355. this.$router.push(this.fun.getUrl("knowledge-knowledge_editor", {}, {
  356. base_id: this.base_id,
  357. parent_id: _data.id
  358. }));
  359. },
  360. // 编辑
  361. handleRename(_node, _data) {
  362. if (!this.isMember && !this.isManager) {
  363. this.$message.error("暂无权限操作");
  364. return;
  365. }
  366. if (!_node.isEdit) {
  367. this.$set(_node, 'isEdit', true)
  368. }
  369. this.$nextTick(() => {
  370. if (this.$refs['slotTreeInput' + _data[this.NODE_KEY]]) {
  371. this.$refs['slotTreeInput' + _data[this.NODE_KEY]].$refs.input.focus()
  372. }
  373. })
  374. },
  375. // 跳转编辑页
  376. toArticleEditor(node, data) {
  377. if (!this.isMember && !this.isManager) {
  378. this.$message.error("暂无权限操作");
  379. return;
  380. }
  381. let artId = data.id;
  382. let base_id = this.fun.getKey("base_id");
  383. this.$router.push(this.fun.getUrl("knowledge-knowledge_editor", {}, {base_id: base_id, articleId: artId}));
  384. },
  385. // 删除
  386. handleDelete(_node, _data) {
  387. if (!this.isManager) {
  388. this.$message.error("您不是管理员,暂无权限删除");
  389. return;
  390. }
  391. this.$confirm("是否删除?", "提示", {
  392. confirmButtonText: "确认",
  393. cancelButtonText: "取消",
  394. type: "warning"
  395. }).then((res) => {
  396. removeQuery();
  397. }).catch(() => {
  398. });
  399. let removeQuery = () => {// 发送删除请求
  400. this.fun.$get("plugin.message-base.frontend.article.deleteArticle", {article_id: _data.id}, "loading")
  401. .then((response) => {
  402. if (response.result !== 1) {
  403. this.$message.error(response.msg);
  404. return;
  405. }
  406. this.$refs.slotTree.remove(_data)
  407. this.$message.success("删除成功");
  408. });
  409. }
  410. },
  411. // 完成拖拽
  412. handledropNode(before, after, inner, event) {
  413. this.moveRequest(before, after.data.parent_id, after.data, inner);
  414. },
  415. // 接口请求
  416. moveRequest(moveNode, parentId, parentData, inner) {
  417. let json = {
  418. article_id: moveNode.data.id,
  419. parent_id: "",
  420. last_id: "",
  421. base_id: this.select_base
  422. };
  423. if (inner === 'after') {
  424. json = {
  425. article_id: moveNode.data.id,
  426. parent_id: parentId,
  427. last_id: parentData.id,
  428. move_type: '1',
  429. base_id: this.select_base
  430. };
  431. }else if(inner === 'inner'){
  432. json = {
  433. article_id: moveNode.data.id,
  434. parent_id: parentData.id,
  435. last_id: 0,
  436. move_type: '1',
  437. base_id: this.select_base
  438. };
  439. } else if(inner === 'before'){
  440. json = {
  441. article_id: moveNode.data.id,
  442. parent_id: parentId,
  443. last_id: parentData.id,
  444. move_type: '2',
  445. base_id: this.select_base
  446. };
  447. }
  448. console.log(json)
  449. this.fun.$get("plugin.message-base.frontend.article.moveArticle", json, "loading")
  450. .then((response) => {
  451. if (response.result !== 1) {
  452. this.getTreeData(this.base_id, 'move');
  453. this.$message.error(response.msg);
  454. return;
  455. }
  456. if(moveNode.data.id == this.$route.params.articleId) {
  457. this.handleNodeClick({id: this.catalogueTree[0].id})
  458. }
  459. this.dialogTableVisible = false;
  460. this.getTreeData(this.base_id, 'move');
  461. this.$message.success("移动成功");
  462. })
  463. },
  464. // 显示移动弹框
  465. showDialog(_node, _data) {
  466. if (!this.isMember && !this.isManager) {
  467. this.$message.error("暂无权限操作");
  468. return;
  469. }
  470. this.getCanMoveBase(_node, _data)
  471. },
  472. getCanMoveBase(_node, _data) {
  473. this.fun.$get("plugin.message-base.frontend.article.getAllAuthBase", {}, "loading")
  474. .then((response) => {
  475. if (response.result !== 1) {
  476. this.$message.error(response.msg);
  477. return;
  478. }
  479. this.base_options = response.data;
  480. this.dialogTableVisible = true;
  481. this.moveNode = _node;
  482. })
  483. },
  484. changeBase() {
  485. this.getTreeData(this.select_base, 'change')
  486. },
  487. // 弹框点击
  488. clickDialogNode(_data, _node) {
  489. this.parentData = _data;
  490. // this.radio ==0同级添加
  491. // this.radio ==1子级添加
  492. },
  493. // 确定按钮
  494. confirmMove() {
  495. this.moveRequest(this.moveNode, this.radio==1 ? this.parentData.id : this.parentData.parent_id, this.parentData, this.radio?'inner':'after');
  496. },
  497. handleScroll() {
  498. let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  499. let boxHeight = document.getElementById("knowledge-article").offsetHeight + 70;
  500. let clientHeight = -(document.documentElement.clientHeight - boxHeight);
  501. if (scrollTop < clientHeight) {
  502. this.notFixed = true;
  503. } else {
  504. this.notFixed = false;
  505. }
  506. },
  507. }
  508. };
  509. </script>
  510. <style lang="scss" rel="stylesheet/scss" scoped>
  511. .text-over {
  512. overflow: hidden;
  513. white-space: nowrap;
  514. width: 100%;
  515. text-overflow: ellipsis;
  516. }
  517. .left-containe {
  518. background-color: #fafafa;
  519. left: 0;
  520. }
  521. // 滚动条隐藏
  522. .hiddenScroll {
  523. scrollbar-width: none; /* firefox */
  524. -ms-overflow-style: none; /* IE 10+ */
  525. overflow-x: hidden;
  526. overflow-y: scroll;
  527. }
  528. .hiddenScroll::-webkit-scrollbar {
  529. display: none; /* Chrome Safari */
  530. }
  531. .left-containe {
  532. z-index: 2;
  533. position: fixed;
  534. top: 70px;
  535. width: 20vw;
  536. height: calc(100vh - 75px);
  537. border-right: solid 1px #efefef;
  538. overflow-y: scroll;
  539. background-color: #fafafa;
  540. .catalogue {
  541. display: flex;
  542. align-items: center;
  543. justify-content: space-between;
  544. letter-spacing: 1px;
  545. color: #595959;
  546. font-size: 14px;
  547. font-weight: bold;
  548. padding: 15px 25px;
  549. border-bottom: solid 1px #e2e2e2;
  550. margin-bottom: 25px;
  551. }
  552. .catalogue-tree, .synopsis-tree {
  553. padding-left: 15px;
  554. .catalogue-tree-node {
  555. width: 100%;
  556. .node-containe {
  557. display: flex;
  558. width: 100%;
  559. flex-wrap: nowrap;
  560. white-space: nowrap;
  561. padding-right: 10px;
  562. }
  563. .node-text {
  564. flex: 1;
  565. width: 0; // 元素自适应超出隐藏
  566. }
  567. .option-node {
  568. margin-right: 5px;
  569. display: none;
  570. font-size: 15px;
  571. }
  572. }
  573. .catalogue-tree-node:hover .option-node {
  574. display: inline-block;
  575. }
  576. :deep(.el-tree) {
  577. background: transparent;
  578. .el-tree-node__content {
  579. padding: 8px 0;
  580. }
  581. .el-tree-node__label {
  582. font-size: 14px;
  583. letter-spacing: 1px;
  584. color: #595959;
  585. overflow: hidden;
  586. text-overflow: ellipsis;
  587. white-space: nowrap;
  588. }
  589. .el-tree__drop-indicator {
  590. height: 2px;
  591. }
  592. .is-current > .el-tree-node__content .node-text {
  593. color: #66B1FF;
  594. }
  595. .is-current > .el-tree-node__content .el-tree-node__label {
  596. // color: var(--color);
  597. }
  598. }
  599. }
  600. .synopsis-tree {
  601. margin-top: 20px;
  602. border-left: 2px solid #e8e8e8;
  603. }
  604. }
  605. .left-containe.notFixed {
  606. display: none;
  607. /*position: absolute;*/
  608. /*top: 60px;*/
  609. /*height: 100%;*/
  610. }
  611. .scroll-box {
  612. height: 50vh;
  613. overflow-y: scroll;
  614. :deep(.el-tree) {
  615. background: transparent;
  616. .el-tree-node__content {
  617. margin: 6px 0;
  618. .hidden {
  619. display: none;
  620. }
  621. .catalogue-tree-node {
  622. position: relative;
  623. flex: 1;
  624. .node-containe {
  625. display: flex;
  626. width: 100%;
  627. flex-wrap: nowrap;
  628. white-space: nowrap;
  629. .node-text {
  630. flex: 1;
  631. width: 0; // 元素自适应超出隐藏
  632. }
  633. }
  634. }
  635. }
  636. .is-current > .el-tree-node__content {
  637. .catalogue-tree-node {
  638. position: relative;
  639. flex: 1;
  640. .radio-box {
  641. display: block;
  642. }
  643. .el-radio {
  644. font-size: 12px;
  645. margin-right: 0;
  646. margin-left: 10px;
  647. }
  648. .selector-tree-placeholder {
  649. display: block;
  650. position: absolute;
  651. bottom: -5px;
  652. left: 0;
  653. width: 100%;
  654. height: 2px;
  655. background-color: #66B1FF;
  656. }
  657. }
  658. }
  659. .el-tree-node__label {
  660. font-size: 14px;
  661. letter-spacing: 1px;
  662. color: #595959;
  663. overflow: hidden;
  664. text-overflow: ellipsis;
  665. white-space: nowrap;
  666. }
  667. }
  668. }
  669. .dialog-footer {
  670. display: flex;
  671. justify-content: center;
  672. }
  673. </style>