docs.vue 24 KB

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