docs.vue 24 KB

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