knowledge-header.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <template>
  2. <div class="custom-search-header">
  3. <div class="fixed-box">
  4. <div class="header-content">
  5. <div class="left">
  6. <img class="logo" @click="toUrl('home')" v-if="basicSet.set" :src="basicSet.set.logo_src" alt="">
  7. <!-- <div class="breadcrumb-box" v-if="breadcrumbs">
  8. <el-breadcrumb separator="/">
  9. <el-breadcrumb-item v-if="breadcrumbs.base">
  10. <span class="hover-class overflow-hide" @click="toUrl('knowledge-home')">知识库首页</span>
  11. </el-breadcrumb-item>
  12. <el-breadcrumb-item v-if="breadcrumbs.base">
  13. <span style="max-width: 300px;display: inline-block" class="hover-class overflow-hide"
  14. @click="toUrl('knowledge-knowledge_detail-articleId', {articleId: -1}, {base_id: breadcrumbs.base.id})">{{breadcrumbs.base.name}}</span>
  15. </el-breadcrumb-item>
  16. <el-breadcrumb-item v-if="breadcrumbs.article">
  17. <span style="max-width: 330px;display: inline-block" class="hover-class overflow-hide"
  18. @click="toUrl('knowledge-knowledge_detail-articleId', {articleId: breadcrumbs.article.id}, {base_id: breadcrumbs.base.id})">{{breadcrumbs.article.name}}</span>
  19. </el-breadcrumb-item>
  20. </el-breadcrumb>
  21. </div> -->
  22. </div>
  23. <div class="tab-list" ref="tabListRef" id="tabListID" @mousewheel.prevent>
  24. <!-- @click="onClickTab(index,$event)" -->
  25. <div class="tab"
  26. :ref="`tabChild_${index}`"
  27. :class="{'tab-selected':tabSelectedIndex===index}"
  28. v-for="(tab,index) in tabList"
  29. @click="toArticle(tab.id,-1)" :key="tab.id" @mousewheel.prevent>
  30. {{tab.name}}
  31. </div>
  32. </div>
  33. <div style="width: 10vw;"></div>
  34. <div class="right">
  35. <el-input v-model="inputKeyword" placeholder="搜索" @keyup.enter.native="toSeach" size="small">
  36. <template slot="prepend"><i class="el-icon-search"></i></template>
  37. </el-input>
  38. <el-button size="small" class="btn-search" @click="toSeach">搜索知识库</el-button>
  39. <el-button size="small" v-if="baseAuths && (baseAuths.isMember || baseAuths.isManager) && baseAuths.isNoList"
  40. class="btn-edit btn-default" @click="optionNode('new')">新建
  41. </el-button>
  42. <el-button size="small" v-if="baseAuths && (baseAuths.isMember || baseAuths.isManager) && isEditor"
  43. class="btn-edit btn-default" @click="optionNode('save')">发布
  44. </el-button>
  45. <el-button size="small"
  46. v-if="baseAuths && (baseAuths.isMember || baseAuths.isManager) && !isEditor && !baseAuths.isNoList"
  47. class="btn-edit btn-default" @click="optionNode('edit')">编辑
  48. </el-button>
  49. <el-button size="small" v-if="baseAuths && baseAuths.isManager" class="btn-delete btn-default"
  50. @click="optionNode('delete')">删除
  51. </el-button>
  52. <el-button size="small" class="btn-login btn-default" v-if="!basicSet.is_login"
  53. @click="toUrl('login',{select: '1'})">登录
  54. </el-button>
  55. <el-button size="small" class="btn-login logout btn-default" @click="toUrl('order')" v-else>个人中心</el-button>
  56. </div>
  57. </div>
  58. </div>
  59. <div class="empty"></div>
  60. <el-dialog title="发布到..."
  61. :visible.sync="dialogTableVisible"
  62. :lock-scroll="true"
  63. >
  64. <div class="scroll-box">
  65. <el-input v-model="article_sort" placeholder="请输入文章排序(数字越大排序越前,默认0)">
  66. </el-input>
  67. <el-tree
  68. highlight-current
  69. :node-key="NODE_KEY"
  70. :data="catalogueTree"
  71. :props="catalogueProps"
  72. :default-expand-all="true"
  73. :expand-on-click-node="false"
  74. :current-node-key="article_id"
  75. @node-click="clickDialogNode"
  76. >
  77. <div class="catalogue-tree-node" slot-scope="{ node, data }">
  78. <div class="node-containe">
  79. <span class="node-text text-over">
  80. {{node.label}}
  81. </span>
  82. <div class="hidden radio-box">
  83. <span style="color:#bfbfbf">移动为</span>
  84. <el-radio-group v-model="radio">
  85. <el-radio :label="0">同级</el-radio>
  86. <el-radio :label="1">子级</el-radio>
  87. </el-radio-group>
  88. </div>
  89. <div class="hidden selector-tree-placeholder" :style="{left: radio==1?'25px':'',width: radio==1?'96%':''}"></div>
  90. </div>
  91. </div>
  92. </el-tree>
  93. </div>
  94. <span slot="footer" class="dialog-footer">
  95. <el-button @click="dialogTableVisible = false">取 消</el-button>
  96. <el-button type="primary" @click="confirmSave">确 定</el-button>
  97. </span>
  98. </el-dialog>
  99. </div>
  100. </template>
  101. <script>
  102. import {mapState} from 'vuex'
  103. export default {
  104. name: "KHeader",
  105. data() {
  106. return {
  107. tabList: [],
  108. tabSelectedIndex: 0,
  109. tabListRef: null,
  110. isEditor: false,
  111. inputKeyword: "",
  112. radio: 0,
  113. article_sort: "",
  114. parentData: "",
  115. // 目录
  116. catalogueTree: [],
  117. catalogueProps: {
  118. label: "article_name",
  119. children: "child",
  120. },
  121. // 树节点参数
  122. NODE_KEY: 'id',
  123. dialogTableVisible: false,
  124. };
  125. },
  126. computed: {
  127. ...mapState(['basicSet', 'basicCategory', 'breadcrumbs', 'baseAuths', 'articleContent']),
  128. article_id() {
  129. if (this.breadcrumbs.article && this.breadcrumbs.article.id) {
  130. return this.breadcrumbs.article.id
  131. } else {
  132. return 0
  133. }
  134. },
  135. },
  136. watch: {
  137. '$route'(res) {
  138. this.url = this.fun.redirectH5(this.$route.path, this.$route.fullPath);
  139. if(location.href.indexOf('knowledge_editor')>-1) {
  140. this.isEditor = true;
  141. }else {
  142. this.isEditor = false;
  143. }
  144. }
  145. },
  146. mounted() {
  147. // PC跳转移动端
  148. this.url = this.fun.redirectH5(this.$route.path, this.$route.fullPath);
  149. if(location.href.indexOf('knowledge_editor')>-1) {
  150. this.isEditor = true;
  151. }
  152. this.getTabData();
  153. },
  154. destroyed() {
  155. let box = document.querySelector("#tabListID")
  156. // 由于不同的浏览器所兼容的函数不同,所以需要首先判断浏览器类型,再按照不同浏览器写不同的函数
  157. let explorer =navigator.userAgent;
  158. if(explorer.indexOf("Firefox") >= 0){
  159. box.removeEventListener("DOMMouseScroll",this.throttleFn)
  160. }else{
  161. box.removeEventListener("mousewheel",this.throttleFn)
  162. }
  163. },
  164. methods: {
  165. toSeach() {
  166. this.$router.push(this.fun.getUrl("knowledge-knowledge_search", {}, {keyword: this.inputKeyword}))
  167. },
  168. toUrl(url, params, query) {
  169. if (url == 'login') {
  170. sessionStorage.setItem("yz_redirect", document.location.href);
  171. }
  172. if (url == 'knowledge-knowledge_detail-articleId' && params.articleId != -1) {
  173. this.$store.commit('setKnowledgeLoading', true);
  174. }
  175. this.$router.push(this.fun.getUrl(url, params, query));
  176. },
  177. logout() {
  178. this.fun.$get("member.logout.index").then(
  179. response => {
  180. if (response.result == 1) {
  181. sessionStorage.setItem("yz_redirect", document.location.href);
  182. this.$store.commit("setLogin", {is_login: false});
  183. this.$alert(response.msg, '提示', {
  184. confirmButtonText: '确定',
  185. callback: action => {
  186. this.$router.push(this.fun.getUrl("login"));
  187. }
  188. });
  189. }
  190. },
  191. response => {
  192. console.log(response.msg);
  193. }
  194. );
  195. },
  196. optionNode(type) {
  197. let artId = this.article_id || this.$route.params.articleId;
  198. let base_id = this.fun.getKey("base_id");
  199. if (!base_id) {
  200. this.$message.error("知识库不存在");
  201. return;
  202. }
  203. if (!artId && type != "save") {
  204. this.$message.error("文章不存在");
  205. return;
  206. }
  207. if (type == 'new') this.editArticle(base_id, -1);
  208. if (type == "edit") this.editArticle(base_id, artId);
  209. if (type == "delete") this.deleteArticle(artId);
  210. if (type == "save") this.saveArticle(base_id, artId);
  211. },
  212. editArticle(base_id, artId) {
  213. this.$router.push(this.fun.getUrl("knowledge-knowledge_editor", {}, {base_id: base_id, articleId: artId}));
  214. },
  215. deleteArticle(artId) {
  216. this.$confirm("是否删除此节点?", "提示", {
  217. confirmButtonText: "确认",
  218. cancelButtonText: "取消",
  219. type: "warning"
  220. }).then((res) => {
  221. removeQuery();
  222. }).catch(() => {
  223. })
  224. let removeQuery = () => {// 发送删除请求
  225. this.fun.$get("plugin.message-base.frontend.article.deleteArticle", {article_id: artId}, "loading")
  226. .then((response) => {
  227. if (response.result !== 1) {
  228. this.$message.error(response.msg);
  229. return false;
  230. }
  231. this.$message.success("删除节点成功");
  232. });
  233. }
  234. },
  235. // 目录树结构
  236. saveArticle(base_id, artId) {
  237. if ((this.article_id && this.article_id != -1) || this.$route.query.parent_id) {
  238. // 暂时只有编辑或者新建子级
  239. this.confirmSave(base_id);
  240. return;
  241. }
  242. // 知识库目录新建
  243. this.fun.$get("plugin.message-base.frontend.article.baseArticle", {base_id: base_id}, "loading")
  244. .then((response) => {
  245. if (response.result !== 1) {
  246. this.$message.error(response.msg);
  247. return false;
  248. }
  249. this.catalogueTree = response.data.article_list || 0;
  250. if (this.catalogueTree.length > 0) {
  251. this.dialogTableVisible = true;
  252. this.$nextTick(() => {
  253. //默认选中
  254. if (this.$refs.slotTree) this.$refs.slotTree.setCurrentKey(artId);
  255. })
  256. } else {
  257. this.confirmSave()
  258. }
  259. })
  260. },
  261. // 弹框节点点击
  262. clickDialogNode(_data, _node) {
  263. this.parentData = _data;
  264. // this.radio ==0同级添加
  265. // this.radio ==1子级添加
  266. },
  267. confirmSave() {
  268. this.dialogTableVisible = false;
  269. if (!this.articleContent.article_name) {
  270. this.$message.error("请输入标题");
  271. document.getElementById('tinymceTitle').focus();
  272. return
  273. }
  274. // 去除字体样式
  275. let articleContent=this.articleContent.content.replace(/font-family.*?;/ig,"");
  276. let parentNodeId = this.radio==1 ? this.parentData.id : this.parentData.parent_id;
  277. let json = {
  278. base_id: this.breadcrumbs.base ? this.breadcrumbs.base.id : this.$route.query.base_id || 1,
  279. parent_id: this.$route.query.parent_id || parentNodeId || 0,
  280. article_name: this.articleContent.article_name,
  281. article: encodeURIComponent(articleContent),
  282. article_sort: this.article_sort,
  283. is_private: this.articleContent.is_private
  284. };
  285. if (this.article_id && this.article_id != -1) {
  286. // 编辑
  287. json = {
  288. article_id: this.article_id,
  289. article_name: this.articleContent.article_name,
  290. article: encodeURIComponent(articleContent) || '',
  291. article_sort: this.article_sort,
  292. is_private: this.articleContent.is_private
  293. };
  294. }
  295. this.fun
  296. .$post('plugin.message-base.frontend.article.changeArticle', json, "正在提交")
  297. .then(res => {
  298. if (res.result === 1) {
  299. this.article_sort = "";
  300. this.$confirm(res.msg, '提示', {
  301. distinguishCancelAndClose: true,
  302. confirmButtonText: '返回知识库',
  303. cancelButtonText: '留在当前页面'
  304. })
  305. .then(() => {
  306. this.toUrl('knowledge-knowledge_detail-articleId', {articleId: res.data.id}, {base_id: res.data.base_id});
  307. })
  308. .catch(action => {
  309. this.$store.commit("setBreadcrumbs", {
  310. base: {
  311. id: this.breadcrumbs.base.id,
  312. name: this.breadcrumbs.base.name
  313. },
  314. article: {
  315. id: res.data.id,
  316. name: res.data.article_name,
  317. }
  318. });
  319. });
  320. } else {
  321. this.$message.error(res.msg);
  322. }
  323. })
  324. .catch(error => {
  325. console.log(error);
  326. });
  327. },
  328. getTabData() {
  329. this.fun.$get("plugin.message-base.frontend.base.firstPage", {show_type: 1}, "加载中")
  330. .then((res) => {
  331. if (res.result !== 1) {
  332. this.$message.error(res.msg);
  333. return;
  334. }
  335. if (res.data.list) {
  336. this.tabList = res.data.list.data||[];
  337. this.tabList.push({
  338. id: 0,
  339. name: '更多'
  340. });
  341. let base_id = this.fun.getKey("base_id");
  342. this.tabList.forEach((element,i) => {
  343. if(element.id == base_id){
  344. this.tabSelectedIndex = i;
  345. }
  346. });
  347. this.handleTabScroll();
  348. this.$nextTick(()=>{
  349. setTimeout(() => {
  350. this.onClickTab();
  351. }, 80);
  352. });
  353. }
  354. })
  355. },
  356. handleTabScroll(){
  357. // 处理顶部导航 的 鼠标左右滚动
  358. let box = document.querySelector("#tabListID")
  359. // 由于不同的浏览器所兼容的函数不同,所以需要首先判断浏览器类型,再按照不同浏览器写不同的函数
  360. let explorer = navigator.userAgent;
  361. if(explorer.indexOf("Firefox") >= 0){
  362. box.addEventListener("DOMMouseScroll",this.throttleFn, true)
  363. }else{
  364. box.addEventListener("mousewheel",this.throttleFn, true)
  365. }
  366. },
  367. NavsListener(box,explorer){
  368. if(!event) return;
  369. if(explorer.indexOf("Firefox") >= 0){
  370. //计算鼠标滚轮滚动的距离
  371. // event.detail * 40 代表幅度(速度),40可以更改
  372. box.scrollLeft += event.detail * 40;
  373. //阻止浏览器默认方法
  374. event.preventDefault();
  375. } else {
  376. //计算鼠标滚轮滚动的距离
  377. // -event.wheelDelta / 2 代表幅度(速度),2可以更改
  378. let v = -event.wheelDelta*3 ;
  379. box.scrollLeft += v;
  380. //阻止浏览器默认方法
  381. event.preventDefault();
  382. }
  383. },
  384. onClickTab(index,e) {
  385. // this.tabSelectedIndex=index
  386. this.tabListRef = this.$refs.tabListRef;
  387. if(!this.$refs[`tabChild_${this.tabSelectedIndex}`]) return;
  388. let target = this.$refs[`tabChild_${this.tabSelectedIndex}`][0];
  389. this.tabListRef.scrollLeft = target.offsetLeft -this.tabListRef.offsetLeft -(this.tabListRef.clientWidth-target.offsetWidth)/2;
  390. },
  391. toArticle(base_id, article_id) {
  392. let url = this.fun.getSiteRoot() + `/plugins/shop_server/knowledge/knowledge_detail/${article_id}?i=${this.fun.getKeyByI()}&base_id=${base_id}`;
  393. if(base_id == 0) {
  394. url = this.fun.getSiteRoot() + `/plugins/shop_server/knowledge/knowledge_whole?i=${this.fun.getKeyByI()}`;
  395. }
  396. // this.$router.push(this.fun.getUrl("knowledge-knowledge_detail", {}, {base_id: base_id, articleId: articleId}));
  397. window.open(url, "_self");
  398. },
  399. throttleFn() {
  400. // 节流
  401. let interval = 200;
  402. this.now = + new Date();
  403. let box = document.querySelector("#tabListID")
  404. // 由于不同的浏览器所兼容的函数不同,所以需要首先判断浏览器类型,再按照不同浏览器写不同的函数
  405. let explorer =navigator.userAgent;
  406. if (this.last && this.now - this.last < interval) {
  407. clearTimeout(this.timer);
  408. this.timer = setTimeout(() => {
  409. this.last = this.now;
  410. this.NavsListener(box,explorer);
  411. }, interval);
  412. } else {
  413. this.last = this.now;
  414. this.NavsListener(box,explorer);
  415. }
  416. },
  417. },
  418. components: {},
  419. };
  420. </script>
  421. <style lang='scss' rel='stylesheet/scss' scoped>
  422. .custom-search-header {
  423. min-width: 1300px;
  424. height: 60px;
  425. padding: 4px;
  426. box-sizing: border-box;
  427. .empty {
  428. width: 100%;
  429. height: 100%;
  430. }
  431. .fixed-box {
  432. z-index: 999;
  433. position: fixed;
  434. top: 0;
  435. left: 0;
  436. width: 100%;
  437. background-color: #ffffff;
  438. box-shadow: 0px 3px 7px 0px rgba(234, 234, 234, 0.81);
  439. }
  440. .header-content {
  441. /*max-width: 1300px;*/
  442. padding: 0 30px;
  443. height: 60px;
  444. margin: 0 auto;
  445. display: flex;
  446. justify-content: space-between;
  447. align-items: center;
  448. .left {
  449. width: 18vw;
  450. display: flex;
  451. align-items: center;
  452. position: relative;
  453. .logo {
  454. cursor: pointer;
  455. width: 220px;
  456. height: 32px;
  457. }
  458. .breadcrumb-box {
  459. margin-left: 20px;
  460. }
  461. .hover-class {
  462. cursor: pointer;
  463. }
  464. .hover-class:hover {
  465. color: var(--color);
  466. }
  467. }
  468. .right {
  469. display: flex;
  470. align-items: center;
  471. :deep(.el-input) {
  472. .el-input-group__prepend {
  473. padding: 0 12px;
  474. background: transparent;
  475. border: 1px solid #DCDFE6;
  476. border-right: none !important;
  477. }
  478. .el-input__inner {
  479. padding-left: 5px;
  480. border-left: none;
  481. }
  482. }
  483. .btn-search {
  484. z-index: 2;
  485. height: 32px;
  486. border: none;
  487. margin-left: -3px;
  488. color: #ffffff;
  489. background-color: var(--color);
  490. }
  491. .btn-default {
  492. border: none;
  493. color: #ffffff;
  494. }
  495. .btn-edit {
  496. background-color: #298DF8;
  497. }
  498. .btn-delete {
  499. background-color: #E1564C;
  500. }
  501. .btn-login {
  502. background-color: #3a75f4;
  503. }
  504. }
  505. }
  506. .tab-list{
  507. flex: 1;
  508. font-size: 16px;
  509. display:flex;
  510. height: 60px;
  511. line-height: 60px;
  512. overflow-x:scroll;
  513. scroll-behavior:smooth;
  514. }
  515. .tab-list::-webkit-scrollbar{
  516. display:none;
  517. }
  518. .tab{
  519. flex:none;
  520. margin: 0 12px;
  521. text-align:center;
  522. color: #333;
  523. cursor: pointer;
  524. }
  525. .tab-selected{
  526. font-weight:bold;
  527. position: relative;
  528. }
  529. .tab-selected{
  530. font-weight:bold;
  531. position: relative;
  532. }
  533. .tab-selected:after {
  534. content: "";
  535. position: absolute;
  536. left: 0;
  537. bottom: 0;
  538. width: 100%;
  539. height: 3px;
  540. background-color: #000000;
  541. z-index: 1;
  542. }
  543. }
  544. .scroll-box {
  545. height: 50vh;
  546. overflow-y: scroll;
  547. :deep(.el-tree) {
  548. background: transparent;
  549. .el-tree-node__content {
  550. margin: 6px 0;
  551. .hidden {
  552. display: none;
  553. }
  554. .catalogue-tree-node {
  555. position: relative;
  556. flex: 1;
  557. .node-containe {
  558. display: flex;
  559. width: 100%;
  560. flex-wrap: nowrap;
  561. white-space: nowrap;
  562. .node-text {
  563. flex: 1;
  564. width: 0; // 元素自适应超出隐藏
  565. }
  566. }
  567. }
  568. }
  569. .is-current > .el-tree-node__content {
  570. .catalogue-tree-node {
  571. position: relative;
  572. flex: 1;
  573. .radio-box {
  574. display: block;
  575. }
  576. .el-radio {
  577. font-size: 12px;
  578. margin-right: 0;
  579. margin-left: 10px;
  580. }
  581. .selector-tree-placeholder {
  582. display: block;
  583. position: absolute;
  584. bottom: -5px;
  585. left: 0;
  586. width: 100%;
  587. height: 2px;
  588. background-color: #66B1FF;
  589. }
  590. }
  591. }
  592. .el-tree-node__label {
  593. font-size: 14px;
  594. letter-spacing: 1px;
  595. color: #595959;
  596. overflow: hidden;
  597. text-overflow: ellipsis;
  598. white-space: nowrap;
  599. }
  600. }
  601. }
  602. </style>