docs.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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. }
  276. }, false);
  277. },
  278. deactivated() {
  279. this.addBookShow = false;
  280. this.addSectionShow = false;
  281. },
  282. computed: {
  283. },
  284. watch: {
  285. addBookShow(val) {
  286. if (val && this.addBookId > 0) {
  287. let tempLists = this.bookLists.filter((res) => { return res.id == this.addBookId });
  288. if (tempLists.length === 1) {
  289. this.$set(this.formBookAdd, 'title', tempLists[0].title);
  290. } else {
  291. this.$set(this.formBookAdd, 'title', '');
  292. }
  293. }
  294. },
  295. addSectionShow(val) {
  296. if (val && this.addSectionId > 0) {
  297. let tempLists = this.children2lists(this.sectionLists).filter((res) => { return res.id == this.addSectionId });
  298. if (tempLists.length === 1) {
  299. this.$set(this.formSectionAdd, 'title', tempLists[0].title);
  300. } else {
  301. this.$set(this.formSectionAdd, 'title', '');
  302. }
  303. }
  304. }
  305. },
  306. methods: {
  307. children2lists(lists) {
  308. let array = [];
  309. lists.forEach((item) => {
  310. array.push({
  311. id: item.id,
  312. title: item.title
  313. });
  314. array = array.concat(this.children2lists(item.children))
  315. });
  316. return array;
  317. },
  318. getBookLists(resetLoad) {
  319. if (resetLoad === true) {
  320. this.bookListPage = 1;
  321. }
  322. this.loadIng++;
  323. this.bookNoDataText = this.$L("数据加载中.....");
  324. $A.apiAjax({
  325. url: 'docs/book/lists',
  326. data: {
  327. page: Math.max(this.bookListPage, 1),
  328. pagesize: 20,
  329. },
  330. complete: () => {
  331. this.loadIng--;
  332. },
  333. error: () => {
  334. this.bookNoDataText = this.$L("数据加载失败!");
  335. },
  336. success: (res) => {
  337. if (res.ret === 1) {
  338. this.bookLists = res.data.lists;
  339. this.bookListTotal = res.data.total;
  340. this.bookNoDataText = this.$L("没有相关的数据");
  341. if (typeof this.selectBookData.id === "undefined") {
  342. this.selectBookData = this.bookLists[0];
  343. this.getSectionLists();
  344. }
  345. }else{
  346. this.bookLists = [];
  347. this.bookListTotal = 0;
  348. this.bookNoDataText = res.msg;
  349. }
  350. }
  351. });
  352. },
  353. onBookAdd() {
  354. this.$refs.bookAdd.validate((valid) => {
  355. if (valid) {
  356. this.loadIng++;
  357. $A.apiAjax({
  358. url: 'docs/book/add',
  359. data: Object.assign(this.formBookAdd, {id:this.addBookId}),
  360. complete: () => {
  361. this.loadIng--;
  362. },
  363. success: (res) => {
  364. if (res.ret === 1) {
  365. this.addBookShow = false;
  366. this.$Message.success(res.msg);
  367. this.$refs.bookAdd.resetFields();
  368. //
  369. if (this.addBookId > 0) {
  370. this.bookLists.some((item) => {
  371. if (item.id == this.addBookId) {
  372. this.$set(item, 'title', res.data.title);
  373. return true;
  374. }
  375. });
  376. } else {
  377. this.bookLists.unshift(res.data);
  378. this.selectBookData = this.bookLists[0];
  379. this.getSectionLists();
  380. }
  381. }else{
  382. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  383. }
  384. }
  385. });
  386. }
  387. });
  388. },
  389. onBookDelete(bookId) {
  390. this.$Modal.confirm({
  391. title: this.$L('删除知识库'),
  392. content: this.$L('你确定要删除此知识库吗?'),
  393. loading: true,
  394. onOk: () => {
  395. $A.apiAjax({
  396. url: 'docs/book/delete',
  397. data: {
  398. id: bookId
  399. },
  400. error: () => {
  401. this.$Modal.remove();
  402. alert(this.$L('网络繁忙,请稍后再试!'));
  403. },
  404. success: (res) => {
  405. this.$Modal.remove();
  406. this.bookLists.some((item, index) => {
  407. if (item.id == bookId) {
  408. this.bookLists.splice(index, 1);
  409. return true;
  410. }
  411. })
  412. this.selectBookData = this.bookLists[0];
  413. this.getSectionLists();
  414. //
  415. setTimeout(() => {
  416. if (res.ret === 1) {
  417. this.$Message.success(res.msg);
  418. } else {
  419. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  420. }
  421. }, 350);
  422. }
  423. });
  424. }
  425. });
  426. },
  427. getSectionLists(isClear) {
  428. if (isClear === true) {
  429. this.sectionLists = [];
  430. }
  431. let bookid = this.selectBookData.id;
  432. this.loadIng++;
  433. this.sectionNoDataText = this.$L("数据加载中.....");
  434. $A.apiAjax({
  435. url: 'docs/section/lists',
  436. data: {
  437. act: 'edit',
  438. bookid: bookid
  439. },
  440. complete: () => {
  441. this.loadIng--;
  442. },
  443. error: () => {
  444. if (bookid != this.selectBookData.id) {
  445. return;
  446. }
  447. this.sectionNoDataText = this.$L("数据加载失败!");
  448. },
  449. success: (res) => {
  450. if (bookid != this.selectBookData.id) {
  451. return;
  452. }
  453. if (res.ret === 1) {
  454. this.sectionLists = res.data.tree;
  455. this.sectionNoDataText = this.$L("没有相关的数据");
  456. }else{
  457. this.sectionLists = [];
  458. this.sectionNoDataText = res.msg;
  459. }
  460. }
  461. });
  462. },
  463. onSectionAdd() {
  464. this.$refs.sectionAdd.validate((valid) => {
  465. if (valid) {
  466. this.loadIng++;
  467. let bookid = this.selectBookData.id;
  468. $A.apiAjax({
  469. url: 'docs/section/add',
  470. data: Object.assign(this.formSectionAdd, {
  471. id: this.addSectionId,
  472. bookid: bookid,
  473. }),
  474. complete: () => {
  475. this.loadIng--;
  476. },
  477. success: (res) => {
  478. if (bookid != this.selectBookData.id) {
  479. return;
  480. }
  481. if (res.ret === 1) {
  482. this.addSectionShow = false;
  483. this.$Message.success(res.msg);
  484. this.$refs.sectionAdd.resetFields();
  485. //
  486. this.getSectionLists();
  487. }else{
  488. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg });
  489. }
  490. }
  491. });
  492. }
  493. });
  494. },
  495. onSectionDelete(sectionId) {
  496. this.$Modal.confirm({
  497. title: this.$L('删除文档'),
  498. content: this.$L('你确定要删除此文档吗?'),
  499. loading: true,
  500. onOk: () => {
  501. $A.apiAjax({
  502. url: 'docs/section/delete',
  503. data: {
  504. id: sectionId
  505. },
  506. error: () => {
  507. this.$Modal.remove();
  508. alert(this.$L('网络繁忙,请稍后再试!'));
  509. },
  510. success: (res) => {
  511. this.$Modal.remove();
  512. this.getSectionLists();
  513. //
  514. setTimeout(() => {
  515. if (res.ret === 1) {
  516. this.$Message.success(res.msg);
  517. } else {
  518. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  519. }
  520. }, 350);
  521. }
  522. });
  523. }
  524. });
  525. },
  526. handleSection(act, detail) {
  527. switch (act) {
  528. case 'open':
  529. this.goForward({name: 'docs-edit', params: {sid:detail.id, other:detail||{}}});
  530. break;
  531. case 'edit':
  532. this.addSectionId = detail.id;
  533. this.addSectionShow = true
  534. break;
  535. case 'add':
  536. this.addSectionId = detail.id * -1;
  537. this.addSectionShow = true
  538. break;
  539. case 'delete':
  540. this.onSectionDelete(detail.id);
  541. break;
  542. case 'sort':
  543. this.sortDisabled = true;
  544. $A.apiAjax({
  545. url: 'docs/section/sort',
  546. data: {
  547. bookid: this.selectBookData.id,
  548. newsort: detail,
  549. },
  550. complete: () => {
  551. this.sortDisabled = false;
  552. },
  553. error: () => {
  554. this.getSectionLists();
  555. alert(this.$L('网络繁忙,请稍后再试!'));
  556. },
  557. success: (res) => {
  558. if (res.ret === 1) {
  559. this.$Message.success(res.msg);
  560. } else {
  561. this.getSectionLists();
  562. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  563. }
  564. }
  565. });
  566. break;
  567. }
  568. },
  569. showShare() {
  570. this.$Modal.confirm({
  571. render: (h) => {
  572. return h('div', [
  573. h('div', {
  574. style: {
  575. fontSize: '16px',
  576. fontWeight: '500',
  577. marginBottom: '20px',
  578. }
  579. }, this.$L('文档链接')),
  580. h('Input', {
  581. props: {
  582. value: $A.webUrl('docs/view/b' + this.selectBookData.id),
  583. readonly: true,
  584. },
  585. })
  586. ])
  587. },
  588. });
  589. }
  590. },
  591. }
  592. </script>