docs.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. <template>
  2. <div class="w-main docs">
  3. <v-title>{{$L('知识库')}}</v-title>
  4. <div class="w-nav">
  5. <div class="nav-row">
  6. <div class="w-nav-left">
  7. <div class="page-nav-left">
  8. <span class="hover" @click="[addBookId=0,addBookShow=true]"><i class="ft icon">&#xE740;</i> {{$L('新建知识库')}}</span>
  9. <div v-if="loadIng > 0" class="page-nav-loading"><w-loading></w-loading></div>
  10. <div v-else class="page-nav-refresh"><em @click="getBookLists(true)">{{$L('刷新')}}</em></div>
  11. </div>
  12. </div>
  13. <div class="w-nav-flex"></div>
  14. </div>
  15. </div>
  16. <w-content>
  17. <div class="docs-main">
  18. <div class="docs-body">
  19. <div class="docs-menu">
  20. <h3>{{$L('我的知识库')}}</h3>
  21. <ul>
  22. <li v-for="book in bookLists" :class="{active:book.id==selectBookData.id}" @click="[selectBookData=book,getSectionLists(true)]">
  23. <div class="docs-title">{{book.title}}</div>
  24. <div class="docs-time">{{$A.formatDate("Y-m-d H:i:s", book.indate)}}</div>
  25. </li>
  26. <li v-if="bookHasMorePages" class="more" @click="getBookLists">{{$L('加载下一页...')}}</li>
  27. <li v-else-if="bookLoading" class="load"><WLoading/></li>
  28. <li v-else-if="bookLists.length == 0" class="none">{{bookNoDataText}}</li>
  29. </ul>
  30. </div>
  31. <div class="docs-container">
  32. <div v-if="selectBookData.id > 0" class="docs-box">
  33. <div class="docs-header">
  34. <div class="docs-h1">{{selectBookData.title}}</div>
  35. <div class="docs-setting">
  36. <Button @click="[addSectionId=0,addSectionShow=true]">{{$L('新增章节')}}</Button>
  37. <Button @click="[addBookId=selectBookData.id,addBookShow=true]">{{$L('修改标题')}}</Button>
  38. <Button @click="showShare">{{$L('分享')}}</Button>
  39. <Button @click="[settingDrawerShow=true,settingDrawerTab='setting']">{{$L('设置')}}</Button>
  40. <Button type="warning" ghost @click="onBookDelete(selectBookData.id)">{{$L('删除')}}</Button>
  41. </div>
  42. </div>
  43. <div class="docs-section">
  44. <nested-draggable :lists="sectionLists" :disabled="sortDisabled" @change="handleSection"></nested-draggable>
  45. <div v-if="sectionLists.length == 0" class="none">{{sectionNoDataText}}</div>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </w-content>
  52. <Modal
  53. v-model="addBookShow"
  54. :title="$L(addBookId > 0 ? '修改标题' : '新建知识库')"
  55. :closable="false"
  56. :mask-closable="false"
  57. class-name="simple-modal">
  58. <Form ref="bookAdd" :model="formBookAdd" :rules="ruleBookAdd" :label-width="110" @submit.native.prevent>
  59. <FormItem prop="title" :label="$L('知识库名称')" style="margin-right:28px">
  60. <Input type="text" v-model="formBookAdd.title" :maxlength="32"></Input>
  61. </FormItem>
  62. </Form>
  63. <div slot="footer">
  64. <Button type="default" @click="addBookShow=false">{{$L('取消')}}</Button>
  65. <Button type="primary" :loading="loadIng > 0" @click="onBookAdd">{{$L(addBookId > 0 ? '提交' : '添加')}}</Button>
  66. </div>
  67. </Modal>
  68. <Modal
  69. v-model="addSectionShow"
  70. :title="$L(addSectionId > 0 ? '修改文档标题' : '新建文档')"
  71. :closable="false"
  72. :mask-closable="false"
  73. class-name="simple-modal">
  74. <Form ref="sectionAdd" :model="formSectionAdd" :rules="ruleSectionAdd" :label-width="110" @submit.native.prevent>
  75. <FormItem prop="title" :label="$L('文档标题')" style="margin-right:28px">
  76. <Input type="text" v-model="formSectionAdd.title" :maxlength="32"></Input>
  77. </FormItem>
  78. <FormItem v-if="addSectionId <= 0" prop="type" :label="$L('文档类型')" style="margin-right:28px">
  79. <ButtonGroup>
  80. <Button v-for="(it, ik) in sectionTypeLists"
  81. :key="ik"
  82. :type="`${formSectionAdd.type==it.value?'primary':'default'}`"
  83. @click="formSectionAdd.type=it.value">{{it.text}}</Button>
  84. </ButtonGroup>
  85. </FormItem>
  86. </Form>
  87. <div slot="footer">
  88. <Button type="default" @click="addSectionShow=false">{{$L('取消')}}</Button>
  89. <Button type="primary" :loading="loadIng > 0" @click="onSectionAdd">{{$L(addSectionId > 0 ? '提交' : '添加')}}</Button>
  90. </div>
  91. </Modal>
  92. <WDrawer v-model="settingDrawerShow" maxWidth="750">
  93. <Tabs v-if="settingDrawerShow" v-model="settingDrawerTab">
  94. <TabPane :label="$L('文档设置')" name="setting">
  95. <book-setting :canload="settingDrawerShow && settingDrawerTab == 'setting'" :id="selectBookData.id" @on-setting-callback="settingCallback"></book-setting>
  96. </TabPane>
  97. <TabPane :label="$L('文档成员')" name="member">
  98. <book-users :canload="settingDrawerShow && settingDrawerTab == 'member'" :id="selectBookData.id"></book-users>
  99. </TabPane>
  100. </Tabs>
  101. </WDrawer>
  102. </div>
  103. </template>
  104. <style lang="scss" scoped>
  105. .docs {
  106. .docs-main {
  107. display: flex;
  108. flex-direction: column;
  109. width: 100%;
  110. min-width: 1024px;
  111. height: 100%;
  112. padding: 15px;
  113. .docs-body {
  114. display: flex;
  115. flex-direction: row;
  116. width: 100%;
  117. height: 100%;
  118. min-height: 500px;
  119. .docs-menu {
  120. display: flex;
  121. flex-direction: column;
  122. width: 230px;
  123. border-radius: 3px 0 0 3px;
  124. background: rgba(255, 255, 255, 0.8);
  125. h3 {
  126. font-size: 18px;
  127. font-weight: normal;
  128. padding: 10px 12px;
  129. color: #333333;
  130. }
  131. ul {
  132. flex: 1;
  133. overflow: auto;
  134. li {
  135. padding: 12px;
  136. cursor: pointer;
  137. &.more {
  138. text-align: center;
  139. color: #555555;
  140. margin-bottom: 6px;
  141. &:hover {
  142. color: #333333;
  143. }
  144. }
  145. &.load {
  146. text-align: center;
  147. height: 42px;
  148. margin-bottom: 9px;
  149. }
  150. &.none {
  151. background-color: transparent;
  152. text-align: center;
  153. color: #666666;
  154. padding: 8px 18px;
  155. }
  156. &.active {
  157. background-color: #ffffff;
  158. }
  159. .docs-title {
  160. color: #242424;
  161. font-size: 13px;
  162. }
  163. .docs-time {
  164. display: block;
  165. color: #999;
  166. font-size: 12px;
  167. margin-top: 2px;
  168. position: relative;
  169. }
  170. }
  171. }
  172. }
  173. .docs-container {
  174. flex: 1;
  175. background-color: #ffffff;
  176. border-radius: 0 3px 3px 0;
  177. .docs-box {
  178. width: 100%;
  179. height: 100%;
  180. display: flex;
  181. flex-direction: column;
  182. }
  183. .docs-header {
  184. display: flex;
  185. align-items: center;
  186. margin: 6px 24px 0;
  187. padding: 12px 0;
  188. border-bottom: 1px solid #eeeeee;
  189. .docs-h1 {
  190. flex: 1;
  191. font-size: 16px;
  192. white-space: nowrap;
  193. }
  194. .docs-setting {
  195. display: flex;
  196. align-items: center;
  197. > button {
  198. margin: 0 6px;
  199. &:last-child {
  200. margin-right: 0;
  201. }
  202. }
  203. }
  204. }
  205. .docs-section {
  206. flex: 1;
  207. padding: 12px 26px;
  208. overflow: auto;
  209. transform: translateZ(0);
  210. .none {
  211. background-color: transparent;
  212. text-align: center;
  213. color: #666666;
  214. padding: 48px 24px;
  215. }
  216. }
  217. }
  218. }
  219. }
  220. }
  221. </style>
  222. <script>
  223. import WContent from "../components/WContent";
  224. import NestedDraggable from "../components/docs/NestedDraggable";
  225. import BookSetting from "../components/docs/setting";
  226. import BookUsers from "../components/docs/users";
  227. import WDrawer from "../components/iview/WDrawer";
  228. export default {
  229. components: {WDrawer, BookUsers, BookSetting, NestedDraggable, WContent},
  230. data () {
  231. return {
  232. loadIng: 0,
  233. bookLists: [],
  234. bookListPage: 1,
  235. bookListTotal: 0,
  236. bookLoading: false,
  237. bookHasMorePages: false,
  238. bookNoDataText: "",
  239. addBookId: 0,
  240. addBookShow: false,
  241. formBookAdd: {
  242. title: '',
  243. },
  244. ruleBookAdd: {},
  245. selectBookData: {},
  246. sectionLists: [],
  247. sectionNoDataText: "",
  248. addSectionId: 0,
  249. addSectionShow: false,
  250. formSectionAdd: {
  251. title: '',
  252. type: 'document',
  253. },
  254. ruleSectionAdd: {},
  255. sectionTypeLists: [],
  256. sortDisabled: false,
  257. settingDrawerShow: false,
  258. settingDrawerTab: 'setting',
  259. }
  260. },
  261. mounted() {
  262. this.getBookLists(true);
  263. },
  264. deactivated() {
  265. this.addBookShow = false;
  266. this.addSectionShow = false;
  267. },
  268. computed: {
  269. },
  270. watch: {
  271. usrName() {
  272. this.usrLogin && this.getBookLists(true);
  273. },
  274. addBookShow(val) {
  275. if (val && this.addBookId > 0) {
  276. let tempLists = this.bookLists.filter((res) => { return res.id == this.addBookId });
  277. if (tempLists.length === 1) {
  278. this.$set(this.formBookAdd, 'title', tempLists[0].title);
  279. } else {
  280. this.$set(this.formBookAdd, 'title', '');
  281. }
  282. }
  283. },
  284. addSectionShow(val) {
  285. if (val && this.addSectionId > 0) {
  286. let tempLists = this.children2lists(this.sectionLists).filter((res) => { return res.id == this.addSectionId });
  287. if (tempLists.length === 1) {
  288. this.$set(this.formSectionAdd, 'title', tempLists[0].title);
  289. } else {
  290. this.$set(this.formSectionAdd, 'title', '');
  291. }
  292. }
  293. }
  294. },
  295. methods: {
  296. initLanguage() {
  297. this.bookNoDataText = this.$L("数据加载中.....");
  298. this.sectionNoDataText = this.$L("数据加载中.....");
  299. this.sectionTypeLists = [
  300. {value: 'document', text: this.$L("文本")},
  301. {value: 'mind', text: this.$L("脑图")},
  302. {value: 'sheet', text: this.$L("表格")},
  303. {value: 'flow', text: this.$L("流程图")},
  304. {value: 'folder', text: this.$L("目录")},
  305. ];
  306. this.ruleBookAdd = {
  307. title: [
  308. { required: true, message: this.$L('请填写知识库名称!'), trigger: 'change' },
  309. { type: 'string', min: 2, message: this.$L('知识库名称长度至少2位!'), trigger: 'change' }
  310. ],
  311. };
  312. this.ruleSectionAdd = {
  313. title: [
  314. { required: true, message: this.$L('请填写文档标题!'), trigger: 'change' },
  315. { type: 'string', min: 2, message: this.$L('文档标题长度至少2位!'), trigger: 'change' }
  316. ],
  317. type: [
  318. { required: true },
  319. ],
  320. };
  321. },
  322. children2lists(lists) {
  323. let array = [];
  324. lists.forEach((item) => {
  325. array.push({
  326. id: item.id,
  327. title: item.title
  328. });
  329. array = array.concat(this.children2lists(item.children))
  330. });
  331. return array;
  332. },
  333. getBookLists(resetLoad) {
  334. if (resetLoad === true) {
  335. this.bookListPage = 1;
  336. } else {
  337. if (this.bookHasMorePages === false) {
  338. return;
  339. }
  340. this.bookListPage++;
  341. }
  342. this.bookLoading = true;
  343. this.bookNoDataText = this.$L("数据加载中.....");
  344. this.bookHasMorePages = false;
  345. $A.apiAjax({
  346. url: 'docs/book/lists',
  347. data: {
  348. page: Math.max(this.bookListPage, 1),
  349. pagesize: 20,
  350. },
  351. complete: () => {
  352. this.bookLoading = false;
  353. },
  354. error: () => {
  355. this.bookNoDataText = this.$L("数据加载失败!");
  356. },
  357. success: (res) => {
  358. if (res.ret === 1) {
  359. res.data.lists.forEach((item) => {
  360. let find = this.bookLists.find((t)=>{return t.id==item.id});
  361. if (!find) {
  362. this.bookLists.push(item);
  363. }
  364. });
  365. this.bookListTotal = res.data.total;
  366. this.bookNoDataText = this.$L("没有相关的数据");
  367. this.bookHasMorePages = res.data.hasMorePages;
  368. if (typeof this.selectBookData.id === "undefined") {
  369. this.selectBookData = this.bookLists[0];
  370. this.getSectionLists();
  371. }
  372. } else {
  373. this.bookLists = [];
  374. this.bookListTotal = 0;
  375. this.bookNoDataText = res.msg;
  376. }
  377. }
  378. });
  379. },
  380. onBookAdd() {
  381. this.$refs.bookAdd.validate((valid) => {
  382. if (valid) {
  383. this.loadIng++;
  384. $A.apiAjax({
  385. url: 'docs/book/add',
  386. data: Object.assign(this.formBookAdd, {id:this.addBookId}),
  387. complete: () => {
  388. this.loadIng--;
  389. },
  390. success: (res) => {
  391. if (res.ret === 1) {
  392. this.addBookShow = false;
  393. this.$Message.success(res.msg);
  394. this.$refs.bookAdd.resetFields();
  395. //
  396. if (this.addBookId > 0) {
  397. this.bookLists.some((item) => {
  398. if (item.id == this.addBookId) {
  399. this.$set(item, 'title', res.data.title);
  400. return true;
  401. }
  402. });
  403. } else {
  404. this.bookLists.unshift(res.data);
  405. this.selectBookData = this.bookLists[0];
  406. this.getSectionLists();
  407. }
  408. }else{
  409. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  410. }
  411. }
  412. });
  413. }
  414. });
  415. },
  416. onBookDelete(bookId) {
  417. this.$Modal.confirm({
  418. title: this.$L('删除知识库'),
  419. content: this.$L('你确定要删除此知识库吗?'),
  420. loading: true,
  421. onOk: () => {
  422. $A.apiAjax({
  423. url: 'docs/book/delete',
  424. data: {
  425. id: bookId
  426. },
  427. error: () => {
  428. this.$Modal.remove();
  429. alert(this.$L('网络繁忙,请稍后再试!'));
  430. },
  431. success: (res) => {
  432. this.$Modal.remove();
  433. this.bookLists.some((item, index) => {
  434. if (item.id == bookId) {
  435. this.bookLists.splice(index, 1);
  436. return true;
  437. }
  438. })
  439. this.selectBookData = this.bookLists.length > 0 ? this.bookLists[0] : {};
  440. this.getSectionLists();
  441. //
  442. setTimeout(() => {
  443. if (res.ret === 1) {
  444. this.$Message.success(res.msg);
  445. } else {
  446. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  447. }
  448. }, 350);
  449. }
  450. });
  451. }
  452. });
  453. },
  454. getSectionLists(isClear) {
  455. if (isClear === true) {
  456. this.sectionLists = [];
  457. }
  458. let bookid = this.selectBookData.id;
  459. this.loadIng++;
  460. this.sectionNoDataText = this.$L("数据加载中.....");
  461. $A.apiAjax({
  462. url: 'docs/section/lists',
  463. data: {
  464. act: 'edit',
  465. bookid: bookid
  466. },
  467. complete: () => {
  468. this.loadIng--;
  469. },
  470. error: () => {
  471. if (bookid != this.selectBookData.id) {
  472. return;
  473. }
  474. this.sectionNoDataText = this.$L("数据加载失败!");
  475. },
  476. success: (res) => {
  477. if (bookid != this.selectBookData.id) {
  478. return;
  479. }
  480. if (res.ret === 1) {
  481. this.sectionLists = res.data.tree;
  482. this.sectionNoDataText = this.$L("没有相关的数据");
  483. }else{
  484. this.sectionLists = [];
  485. this.sectionNoDataText = res.msg;
  486. }
  487. }
  488. });
  489. },
  490. onSectionAdd() {
  491. this.$refs.sectionAdd.validate((valid) => {
  492. if (valid) {
  493. this.loadIng++;
  494. let bookid = this.selectBookData.id;
  495. $A.apiAjax({
  496. url: 'docs/section/add',
  497. data: Object.assign(this.formSectionAdd, {
  498. id: this.addSectionId,
  499. bookid: bookid,
  500. }),
  501. complete: () => {
  502. this.loadIng--;
  503. },
  504. success: (res) => {
  505. if (bookid != this.selectBookData.id) {
  506. return;
  507. }
  508. if (res.ret === 1) {
  509. this.addSectionShow = false;
  510. this.$Message.success(res.msg);
  511. this.$refs.sectionAdd.resetFields();
  512. //
  513. this.getSectionLists();
  514. }else{
  515. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  516. }
  517. }
  518. });
  519. }
  520. });
  521. },
  522. onSectionDelete(detail) {
  523. let sectionType = this.sectionTypeLists.find((item) => { return item.value == detail.type });
  524. this.$Modal.confirm({
  525. title: this.$L('删除文档'),
  526. content: this.$L('你确定要删除%【%】吗?', sectionType ? sectionType.text : '', detail.title),
  527. loading: true,
  528. onOk: () => {
  529. $A.apiAjax({
  530. url: 'docs/section/delete',
  531. data: {
  532. id: detail.id
  533. },
  534. error: () => {
  535. this.$Modal.remove();
  536. alert(this.$L('网络繁忙,请稍后再试!'));
  537. },
  538. success: (res) => {
  539. this.$Modal.remove();
  540. this.getSectionLists();
  541. //
  542. setTimeout(() => {
  543. if (res.ret === 1) {
  544. this.$Message.success(res.msg);
  545. } else {
  546. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  547. }
  548. }, 350);
  549. }
  550. });
  551. }
  552. });
  553. },
  554. handleSection(act, detail) {
  555. switch (act) {
  556. case 'open':
  557. this.goForward({name: 'docs-edit', params: {sid:detail.id, other:detail||{}}});
  558. break;
  559. case 'edit':
  560. this.addSectionId = detail.id;
  561. this.addSectionShow = true
  562. break;
  563. case 'add':
  564. this.addSectionId = detail.id * -1;
  565. this.addSectionShow = true
  566. break;
  567. case 'delete':
  568. if (this.sortDisabled) {
  569. this.$Modal.warning({
  570. title: this.$L('温馨提示'),
  571. content: this.$L('正在进行其他操作,请稍后重试...')
  572. });
  573. return;
  574. }
  575. this.onSectionDelete(detail);
  576. break;
  577. case 'sort':
  578. this.sortDisabled = true;
  579. this.loadIng++;
  580. $A.apiAjax({
  581. url: 'docs/section/sort',
  582. data: {
  583. bookid: this.selectBookData.id,
  584. newsort: detail,
  585. },
  586. complete: () => {
  587. this.sortDisabled = false;
  588. this.loadIng--;
  589. },
  590. error: () => {
  591. this.getSectionLists();
  592. alert(this.$L('网络繁忙,请稍后再试!'));
  593. },
  594. success: (res) => {
  595. if (res.ret === 1) {
  596. this.$Message.success(res.msg);
  597. } else {
  598. this.getSectionLists();
  599. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  600. }
  601. }
  602. });
  603. break;
  604. }
  605. },
  606. showShare() {
  607. this.$Modal.confirm({
  608. render: (h) => {
  609. return h('div', [
  610. h('div', {
  611. style: {
  612. fontSize: '16px',
  613. fontWeight: '500',
  614. marginBottom: '20px',
  615. }
  616. }, this.$L('文档链接')),
  617. h('Input', {
  618. props: {
  619. value: $A.webUrl('docs/view/b' + this.selectBookData.id),
  620. readonly: true,
  621. },
  622. })
  623. ])
  624. },
  625. });
  626. },
  627. settingCallback(data) {
  628. let tmpData = this.bookLists.find(({id}) => id == data.id);
  629. if (tmpData) {
  630. $A.each(data, (key, val) => {
  631. this.$set(tmpData, key, val);
  632. });
  633. }
  634. }
  635. },
  636. }
  637. </script>