docs.vue 24 KB

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