docs.vue 26 KB

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