docs.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <template>
  2. <div class="w-main docs">
  3. <v-title>{{$L('知识库')}}-{{$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">
  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">
  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"></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. userInfo: {},
  234. bookLists: [],
  235. bookListPage: 1,
  236. bookListTotal: 0,
  237. bookLoading: false,
  238. bookHasMorePages: false,
  239. bookNoDataText: "",
  240. addBookId: 0,
  241. addBookShow: false,
  242. formBookAdd: {
  243. title: '',
  244. },
  245. ruleBookAdd: {},
  246. selectBookData: {},
  247. sectionLists: [],
  248. sectionNoDataText: "",
  249. addSectionId: 0,
  250. addSectionShow: false,
  251. formSectionAdd: {
  252. title: '',
  253. type: 'document',
  254. },
  255. ruleSectionAdd: {},
  256. sectionTypeLists: [],
  257. sortDisabled: false,
  258. settingDrawerShow: false,
  259. settingDrawerTab: 'setting',
  260. }
  261. },
  262. created() {
  263. this.bookNoDataText = this.$L("数据加载中.....");
  264. this.sectionNoDataText = this.$L("数据加载中.....");
  265. this.sectionTypeLists = [
  266. {value: 'document', text: this.$L("文本")},
  267. {value: 'mind', text: this.$L("脑图")},
  268. {value: 'sheet', text: this.$L("表格")},
  269. {value: 'flow', text: this.$L("流程图")},
  270. {value: 'folder', text: this.$L("目录")},
  271. ];
  272. this.ruleBookAdd = {
  273. title: [
  274. { required: true, message: this.$L('请填写知识库名称!'), trigger: 'change' },
  275. { type: 'string', min: 2, message: this.$L('知识库名称长度至少2位!'), trigger: 'change' }
  276. ],
  277. };
  278. this.ruleSectionAdd = {
  279. title: [
  280. { required: true, message: this.$L('请填写文档标题!'), trigger: 'change' },
  281. { type: 'string', min: 2, message: this.$L('文档标题长度至少2位!'), trigger: 'change' }
  282. ],
  283. type: [
  284. { required: true },
  285. ],
  286. };
  287. },
  288. mounted() {
  289. this.getBookLists(true);
  290. this.userInfo = $A.getUserInfo((res, isLogin) => {
  291. if (this.userInfo.id != res.id) {
  292. this.userInfo = res;
  293. isLogin && this.getBookLists(true);
  294. } else {
  295. this.userInfo = res;
  296. }
  297. }, false);
  298. },
  299. deactivated() {
  300. this.addBookShow = false;
  301. this.addSectionShow = false;
  302. },
  303. computed: {
  304. },
  305. watch: {
  306. addBookShow(val) {
  307. if (val && this.addBookId > 0) {
  308. let tempLists = this.bookLists.filter((res) => { return res.id == this.addBookId });
  309. if (tempLists.length === 1) {
  310. this.$set(this.formBookAdd, 'title', tempLists[0].title);
  311. } else {
  312. this.$set(this.formBookAdd, 'title', '');
  313. }
  314. }
  315. },
  316. addSectionShow(val) {
  317. if (val && this.addSectionId > 0) {
  318. let tempLists = this.children2lists(this.sectionLists).filter((res) => { return res.id == this.addSectionId });
  319. if (tempLists.length === 1) {
  320. this.$set(this.formSectionAdd, 'title', tempLists[0].title);
  321. } else {
  322. this.$set(this.formSectionAdd, 'title', '');
  323. }
  324. }
  325. }
  326. },
  327. methods: {
  328. children2lists(lists) {
  329. let array = [];
  330. lists.forEach((item) => {
  331. array.push({
  332. id: item.id,
  333. title: item.title
  334. });
  335. array = array.concat(this.children2lists(item.children))
  336. });
  337. return array;
  338. },
  339. getBookLists(resetLoad) {
  340. if (resetLoad === true) {
  341. this.bookListPage = 1;
  342. } else {
  343. if (this.bookHasMorePages === false) {
  344. return;
  345. }
  346. this.bookListPage++;
  347. }
  348. this.bookLoading = true;
  349. this.bookNoDataText = this.$L("数据加载中.....");
  350. this.bookHasMorePages = false;
  351. $A.apiAjax({
  352. url: 'docs/book/lists',
  353. data: {
  354. page: Math.max(this.bookListPage, 1),
  355. pagesize: 20,
  356. },
  357. complete: () => {
  358. this.bookLoading = false;
  359. },
  360. error: () => {
  361. this.bookNoDataText = this.$L("数据加载失败!");
  362. },
  363. success: (res) => {
  364. if (res.ret === 1) {
  365. res.data.lists.forEach((item) => {
  366. let find = this.bookLists.find((t)=>{return t.id==item.id});
  367. if (!find) {
  368. this.bookLists.push(item);
  369. }
  370. });
  371. this.bookListTotal = res.data.total;
  372. this.bookNoDataText = this.$L("没有相关的数据");
  373. this.bookHasMorePages = res.data.hasMorePages;
  374. if (typeof this.selectBookData.id === "undefined") {
  375. this.selectBookData = this.bookLists[0];
  376. this.getSectionLists();
  377. }
  378. } else {
  379. this.bookLists = [];
  380. this.bookListTotal = 0;
  381. this.bookNoDataText = res.msg;
  382. }
  383. }
  384. });
  385. },
  386. onBookAdd() {
  387. this.$refs.bookAdd.validate((valid) => {
  388. if (valid) {
  389. this.loadIng++;
  390. $A.apiAjax({
  391. url: 'docs/book/add',
  392. data: Object.assign(this.formBookAdd, {id:this.addBookId}),
  393. complete: () => {
  394. this.loadIng--;
  395. },
  396. success: (res) => {
  397. if (res.ret === 1) {
  398. this.addBookShow = false;
  399. this.$Message.success(res.msg);
  400. this.$refs.bookAdd.resetFields();
  401. //
  402. if (this.addBookId > 0) {
  403. this.bookLists.some((item) => {
  404. if (item.id == this.addBookId) {
  405. this.$set(item, 'title', res.data.title);
  406. return true;
  407. }
  408. });
  409. } else {
  410. this.bookLists.unshift(res.data);
  411. this.selectBookData = this.bookLists[0];
  412. this.getSectionLists();
  413. }
  414. }else{
  415. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  416. }
  417. }
  418. });
  419. }
  420. });
  421. },
  422. onBookDelete(bookId) {
  423. this.$Modal.confirm({
  424. title: this.$L('删除知识库'),
  425. content: this.$L('你确定要删除此知识库吗?'),
  426. loading: true,
  427. onOk: () => {
  428. $A.apiAjax({
  429. url: 'docs/book/delete',
  430. data: {
  431. id: bookId
  432. },
  433. error: () => {
  434. this.$Modal.remove();
  435. alert(this.$L('网络繁忙,请稍后再试!'));
  436. },
  437. success: (res) => {
  438. this.$Modal.remove();
  439. this.bookLists.some((item, index) => {
  440. if (item.id == bookId) {
  441. this.bookLists.splice(index, 1);
  442. return true;
  443. }
  444. })
  445. this.selectBookData = this.bookLists[0];
  446. this.getSectionLists();
  447. //
  448. setTimeout(() => {
  449. if (res.ret === 1) {
  450. this.$Message.success(res.msg);
  451. } else {
  452. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  453. }
  454. }, 350);
  455. }
  456. });
  457. }
  458. });
  459. },
  460. getSectionLists(isClear) {
  461. if (isClear === true) {
  462. this.sectionLists = [];
  463. }
  464. let bookid = this.selectBookData.id;
  465. this.loadIng++;
  466. this.sectionNoDataText = this.$L("数据加载中.....");
  467. $A.apiAjax({
  468. url: 'docs/section/lists',
  469. data: {
  470. act: 'edit',
  471. bookid: bookid
  472. },
  473. complete: () => {
  474. this.loadIng--;
  475. },
  476. error: () => {
  477. if (bookid != this.selectBookData.id) {
  478. return;
  479. }
  480. this.sectionNoDataText = this.$L("数据加载失败!");
  481. },
  482. success: (res) => {
  483. if (bookid != this.selectBookData.id) {
  484. return;
  485. }
  486. if (res.ret === 1) {
  487. this.sectionLists = res.data.tree;
  488. this.sectionNoDataText = this.$L("没有相关的数据");
  489. }else{
  490. this.sectionLists = [];
  491. this.sectionNoDataText = res.msg;
  492. }
  493. }
  494. });
  495. },
  496. onSectionAdd() {
  497. this.$refs.sectionAdd.validate((valid) => {
  498. if (valid) {
  499. this.loadIng++;
  500. let bookid = this.selectBookData.id;
  501. $A.apiAjax({
  502. url: 'docs/section/add',
  503. data: Object.assign(this.formSectionAdd, {
  504. id: this.addSectionId,
  505. bookid: bookid,
  506. }),
  507. complete: () => {
  508. this.loadIng--;
  509. },
  510. success: (res) => {
  511. if (bookid != this.selectBookData.id) {
  512. return;
  513. }
  514. if (res.ret === 1) {
  515. this.addSectionShow = false;
  516. this.$Message.success(res.msg);
  517. this.$refs.sectionAdd.resetFields();
  518. //
  519. this.getSectionLists();
  520. }else{
  521. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  522. }
  523. }
  524. });
  525. }
  526. });
  527. },
  528. onSectionDelete(detail) {
  529. let sectionType = this.sectionTypeLists.find((item) => { return item.value == detail.type });
  530. this.$Modal.confirm({
  531. title: this.$L('删除文档'),
  532. content: this.$L('你确定要删除%【%】吗?', sectionType ? sectionType.text : '', detail.title),
  533. loading: true,
  534. onOk: () => {
  535. $A.apiAjax({
  536. url: 'docs/section/delete',
  537. data: {
  538. id: detail.id
  539. },
  540. error: () => {
  541. this.$Modal.remove();
  542. alert(this.$L('网络繁忙,请稍后再试!'));
  543. },
  544. success: (res) => {
  545. this.$Modal.remove();
  546. this.getSectionLists();
  547. //
  548. setTimeout(() => {
  549. if (res.ret === 1) {
  550. this.$Message.success(res.msg);
  551. } else {
  552. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  553. }
  554. }, 350);
  555. }
  556. });
  557. }
  558. });
  559. },
  560. handleSection(act, detail) {
  561. switch (act) {
  562. case 'open':
  563. this.goForward({name: 'docs-edit', params: {sid:detail.id, other:detail||{}}});
  564. break;
  565. case 'edit':
  566. this.addSectionId = detail.id;
  567. this.addSectionShow = true
  568. break;
  569. case 'add':
  570. this.addSectionId = detail.id * -1;
  571. this.addSectionShow = true
  572. break;
  573. case 'delete':
  574. if (this.sortDisabled) {
  575. this.$Modal.warning({
  576. title: this.$L('温馨提示'),
  577. content: this.$L('正在进行其他操作,请稍后重试...')
  578. });
  579. return;
  580. }
  581. this.onSectionDelete(detail);
  582. break;
  583. case 'sort':
  584. this.sortDisabled = true;
  585. this.loadIng++;
  586. $A.apiAjax({
  587. url: 'docs/section/sort',
  588. data: {
  589. bookid: this.selectBookData.id,
  590. newsort: detail,
  591. },
  592. complete: () => {
  593. this.sortDisabled = false;
  594. this.loadIng--;
  595. },
  596. error: () => {
  597. this.getSectionLists();
  598. alert(this.$L('网络繁忙,请稍后再试!'));
  599. },
  600. success: (res) => {
  601. if (res.ret === 1) {
  602. this.$Message.success(res.msg);
  603. } else {
  604. this.getSectionLists();
  605. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  606. }
  607. }
  608. });
  609. break;
  610. }
  611. },
  612. showShare() {
  613. this.$Modal.confirm({
  614. render: (h) => {
  615. return h('div', [
  616. h('div', {
  617. style: {
  618. fontSize: '16px',
  619. fontWeight: '500',
  620. marginBottom: '20px',
  621. }
  622. }, this.$L('文档链接')),
  623. h('Input', {
  624. props: {
  625. value: $A.webUrl('docs/view/b' + this.selectBookData.id),
  626. readonly: true,
  627. },
  628. })
  629. ])
  630. },
  631. });
  632. }
  633. },
  634. }
  635. </script>