docs.vue 23 KB

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