docs.vue 26 KB

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