docs.vue 24 KB

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