edit.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <template>
  2. <div class="w-main docs-edit">
  3. <v-title>{{$L('文档编辑')}}-{{$L('轻量级的团队在线协作')}}</v-title>
  4. <div class="edit-box">
  5. <div class="edit-header">
  6. <div class="header-menu active" @click="handleClick('back')"><Icon type="md-arrow-back" /></div>
  7. <div class="header-menu" @click="handleClick('menu')"><Icon type="md-menu" /></div>
  8. <!--<div class="header-menu" @click="handleClick('share')"><Icon type="md-share" /></div>
  9. <div class="header-menu" @click="handleClick('view')"><Icon type="md-eye" /></div>-->
  10. <div class="header-menu" @click="handleClick('history')"><Icon type="md-time" /></div>
  11. <div class="header-title">{{docDetail.title}}</div>
  12. <div v-if="docDetail.type=='mind'" class="header-hint">{{$L('选中节点,按enter键添加子节点,tab键添加同级节点')}}</div>
  13. <Button :disabled="(disabledBtn || loadIng > 0) && hid == 0" class="header-button" size="small" type="primary" @click="handleClick('save')">{{$L('保存')}}</Button>
  14. </div>
  15. <div class="docs-body">
  16. <t-editor v-if="docDetail.type=='document'" class="body-text" v-model="docContent.content" height="100%"></t-editor>
  17. <minder v-else-if="docDetail.type=='mind'" class="body-mind" v-model="docContent"></minder>
  18. <sheet v-else-if="docDetail.type=='sheet'" class="body-sheet" v-model="docContent.content"></sheet>
  19. <flow v-else-if="docDetail.type=='flow'" class="body-flow" v-model="docContent.content"></flow>
  20. </div>
  21. </div>
  22. <Drawer v-model="docDrawerShow" width="450">
  23. <Tabs v-if="docDrawerShow" v-model="docDrawerTab">
  24. <TabPane :label="$L('知识库目录')" name="menu">
  25. <nested-draggable :lists="sectionLists" :readonly="true" :activeid="sid" @change="handleSection"></nested-draggable>
  26. <div v-if="sectionLists.length == 0" style="color:#888;padding:32px;text-align:center">{{sectionNoDataText}}</div>
  27. </TabPane>
  28. <TabPane :label="$L('文档历史版本')" name="history">
  29. <Table class="tableFill" :columns="historyColumns" :data="historyLists" :no-data-text="historyNoDataText" size="small" stripe></Table>
  30. </TabPane>
  31. </Tabs>
  32. </Drawer>
  33. </div>
  34. </template>
  35. <style lang="scss">
  36. .docs-edit {
  37. .body-text {
  38. .teditor-loadedstyle {
  39. .tox-tinymce {
  40. border: 0;
  41. border-radius: 0;
  42. }
  43. .tox-mbtn {
  44. height: 28px;
  45. }
  46. .tox-menubar,
  47. .tox-toolbar-overlord {
  48. padding: 0 12%;
  49. background: #f9f9f9;
  50. }
  51. .tox-toolbar__overflow,
  52. .tox-toolbar__primary {
  53. background: none !important;
  54. border-top: 1px solid #eaeaea !important;
  55. }
  56. .tox-toolbar-overlord {
  57. border-bottom: 1px solid #E9E9E9 !important;
  58. }
  59. .tox-toolbar__group:not(:last-of-type) {
  60. border-right: 1px solid #eaeaea !important;
  61. }
  62. .tox-sidebar-wrap {
  63. margin: 22px 12%;
  64. border: 1px solid #e8e8e8;
  65. border-radius: 2px;
  66. box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.08);
  67. .tox-edit-area {
  68. border-top: 0;
  69. }
  70. }
  71. .tox-statusbar {
  72. border-top: 1px solid #E9E9E9;
  73. .tox-statusbar__resize-handle {
  74. display: none;
  75. }
  76. }
  77. }
  78. }
  79. .body-sheet {
  80. box-sizing: content-box;
  81. * {
  82. box-sizing: content-box;
  83. }
  84. }
  85. }
  86. </style>
  87. <style lang="scss" scoped>
  88. .docs-edit {
  89. .edit-box {
  90. display: flex;
  91. flex-direction: column;
  92. position: absolute;
  93. width: 100%;
  94. height: 100%;
  95. .edit-header {
  96. display: flex;
  97. flex-direction: row;
  98. align-items: center;
  99. width: 100%;
  100. height: 38px;
  101. background-color: #ffffff;
  102. box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.1);
  103. position: relative;
  104. z-index: 9;
  105. .header-menu {
  106. width: 50px;
  107. height: 100%;
  108. text-align: center;
  109. display: flex;
  110. align-items: center;
  111. justify-content: center;
  112. margin-right: 3px;
  113. cursor: pointer;
  114. color: #777777;
  115. position: relative;
  116. .ivu-icon {
  117. font-size: 16px;
  118. }
  119. &:hover,
  120. &.active {
  121. color: #fff;
  122. background: #059DFD;
  123. }
  124. }
  125. .header-title {
  126. flex: 1;
  127. color: #333333;
  128. border-left: 1px solid #ddd;
  129. margin-left: 5px;
  130. padding-left: 24px;
  131. padding-right: 24px;
  132. font-size: 16px;
  133. white-space: nowrap;
  134. }
  135. .header-hint {
  136. padding-right: 22px;
  137. font-size: 12px;
  138. color: #666;
  139. white-space: nowrap;
  140. }
  141. .header-button {
  142. font-size: 12px;
  143. margin-right: 12px;
  144. }
  145. }
  146. .docs-body {
  147. flex: 1;
  148. width: 100%;
  149. position: relative;
  150. .body-text {
  151. display: flex;
  152. width: 100%;
  153. height: 100%;
  154. .teditor-loadedstyle {
  155. height: 100%;
  156. }
  157. }
  158. }
  159. }
  160. }
  161. </style>
  162. <script>
  163. import Vue from 'vue'
  164. import minder from '../../components/docs/minder'
  165. import TEditor from "../../components/TEditor";
  166. import Sheet from "../../components/docs/sheet/index";
  167. import Flow from "../../components/docs/flow/index";
  168. import NestedDraggable from "../../components/docs/NestedDraggable";
  169. Vue.use(minder)
  170. export default {
  171. components: {Flow, Sheet, TEditor, NestedDraggable},
  172. data () {
  173. return {
  174. loadIng: 0,
  175. sid: 0,
  176. hid: 0,
  177. docDetail: { },
  178. docContent: { },
  179. bakContent: null,
  180. docDrawerShow: false,
  181. docDrawerTab: '',
  182. sectionLists: [],
  183. sectionNoDataText: "",
  184. historyColumns: [],
  185. historyLists: [],
  186. historyNoDataText: "",
  187. }
  188. },
  189. created() {
  190. this.historyColumns = [{
  191. "title": this.$L("存档日期"),
  192. "minWidth": 160,
  193. "maxWidth": 200,
  194. render: (h, params) => {
  195. return h('span', $A.formatDate("Y-m-d H:i:s", params.row.indate));
  196. }
  197. }, {
  198. "title": this.$L("操作员"),
  199. "key": 'username',
  200. "minWidth": 80,
  201. "maxWidth": 130,
  202. render: (h, params) => {
  203. return h('UserView', {
  204. props: {
  205. username: params.row.username
  206. }
  207. });
  208. }
  209. }, {
  210. "title": " ",
  211. "key": 'action',
  212. "width": 80,
  213. "align": 'center',
  214. render: (h, params) => {
  215. if (this.hid == params.row.id || (this.hid == 0 && params.index == 0)) {
  216. return h('Icon', {
  217. props: { type: 'md-checkmark' },
  218. style: { marginRight: '6px', fontSize: '16px', color: '#FF5722' },
  219. });
  220. }
  221. return h('Button', {
  222. props: {
  223. type: 'text',
  224. size: 'small'
  225. },
  226. style: {
  227. fontSize: '12px'
  228. },
  229. on: {
  230. click: () => {
  231. let data = {sid: this.getSid() + "-" + params.row.id, other: this.$route.params.other}
  232. if (params.index == 0) {
  233. data.sid = this.getSid();
  234. }
  235. this.goForward({name: 'docs-edit', params: data }, true);
  236. this.refreshSid();
  237. this.docDrawerShow = false;
  238. }
  239. }
  240. }, this.$L('还原'));
  241. }
  242. }];
  243. },
  244. mounted() {
  245. },
  246. activated() {
  247. this.refreshSid();
  248. },
  249. deactivated() {
  250. this.docDrawerShow = false;
  251. if ($A.getToken() === false) {
  252. this.sid = 0;
  253. }
  254. },
  255. watch: {
  256. sid(val) {
  257. if (!val) {
  258. this.goBack();
  259. return;
  260. }
  261. this.hid = $A.runNum($A.strExists(val, '-') ? $A.getMiddle(val, "-", null) : 0);
  262. this.docDetail = { };
  263. this.docContent = { };
  264. this.bakContent = null;
  265. this.getDetail();
  266. },
  267. docDrawerTab(act) {
  268. switch (act) {
  269. case "menu":
  270. if (!this.sectionNoDataText) {
  271. this.sectionNoDataText = this.$L("数据加载中.....");
  272. let bookid = this.docDetail.bookid;
  273. $A.aAjax({
  274. url: 'docs/section/lists',
  275. data: {
  276. bookid: bookid
  277. },
  278. error: () => {
  279. if (bookid != this.docDetail.bookid) {
  280. return;
  281. }
  282. this.sectionNoDataText = this.$L("数据加载失败!");
  283. },
  284. success: (res) => {
  285. if (bookid != this.docDetail.bookid) {
  286. return;
  287. }
  288. if (res.ret === 1) {
  289. this.sectionLists = res.data;
  290. this.sectionNoDataText = this.$L("没有相关的数据");
  291. }else{
  292. this.sectionLists = [];
  293. this.sectionNoDataText = res.msg;
  294. }
  295. }
  296. });
  297. }
  298. break;
  299. case "history":
  300. if (!this.historyNoDataText) {
  301. this.historyNoDataText = this.$L("数据加载中.....");
  302. let sid = this.getSid();
  303. $A.aAjax({
  304. url: 'docs/section/history',
  305. data: {
  306. id: sid,
  307. pagesize: 50
  308. },
  309. error: () => {
  310. if (sid != this.getSid()) {
  311. return;
  312. }
  313. this.historyNoDataText = this.$L("数据加载失败!");
  314. },
  315. success: (res) => {
  316. if (sid != this.getSid()) {
  317. return;
  318. }
  319. if (res.ret === 1) {
  320. this.historyLists = res.data;
  321. this.historyNoDataText = this.$L("没有相关的数据");
  322. }else{
  323. this.historyLists = [];
  324. this.historyNoDataText = res.msg;
  325. }
  326. }
  327. });
  328. }
  329. break;
  330. }
  331. }
  332. },
  333. computed: {
  334. disabledBtn() {
  335. return this.bakContent == $A.jsonStringify(this.docContent);
  336. }
  337. },
  338. methods: {
  339. refreshSid() {
  340. this.sid = this.$route.params.sid;
  341. if (typeof this.$route.params.other === "object") {
  342. this.$set(this.docDetail, 'title', $A.getObject(this.$route.params.other, 'title'))
  343. }
  344. },
  345. getSid() {
  346. return $A.runNum($A.getMiddle(this.sid, null, '-'));
  347. },
  348. getDetail() {
  349. this.loadIng++;
  350. $A.aAjax({
  351. url: 'docs/section/content',
  352. data: {
  353. id: this.sid,
  354. },
  355. complete: () => {
  356. this.loadIng--;
  357. },
  358. error: () => {
  359. this.goBack();
  360. alert(this.$L('网络繁忙,请稍后再试!'));
  361. },
  362. success: (res) => {
  363. if (res.ret === 1) {
  364. this.docDetail = res.data;
  365. this.docContent = $A.jsonParse(res.data.content);
  366. this.bakContent = $A.jsonStringify(this.docContent);
  367. } else {
  368. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  369. this.goBack();
  370. }
  371. }
  372. });
  373. },
  374. handleSection(act, detail) {
  375. if (act === 'open') {
  376. this.goForward({name: 'docs-edit', params: {sid: detail.id, other: detail || {}}}, true);
  377. this.refreshSid();
  378. this.docDrawerShow = false;
  379. }
  380. },
  381. handleClick(act) {
  382. switch (act) {
  383. case "back":
  384. if (this.bakContent == $A.jsonStringify(this.docContent) && this.hid == 0) {
  385. this.goBack();
  386. return;
  387. }
  388. this.$Modal.confirm({
  389. title: this.$L('温馨提示'),
  390. content: this.$L('是否放弃修改的内容返回?'),
  391. loading: true,
  392. cancelText: this.$L('放弃保存'),
  393. onCancel: () => {
  394. this.goBack();
  395. },
  396. okText: this.$L('保存并返回'),
  397. onOk: () => {
  398. this.bakContent = $A.jsonStringify(this.docContent);
  399. $A.aAjax({
  400. url: 'docs/section/save?id=' + this.getSid(),
  401. method: 'post',
  402. data: {
  403. D: Object.assign(this.docDetail, {content: this.bakContent})
  404. },
  405. error: () => {
  406. this.$Modal.remove();
  407. alert(this.$L('网络繁忙,请稍后再试!'));
  408. },
  409. success: (res) => {
  410. this.$Modal.remove();
  411. this.goBack();
  412. setTimeout(() => {
  413. if (res.ret === 1) {
  414. this.$Message.success(res.msg);
  415. this.historyNoDataText = '';
  416. } else {
  417. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  418. }
  419. }, 350);
  420. }
  421. });
  422. }
  423. });
  424. break;
  425. case "save":
  426. this.bakContent = $A.jsonStringify(this.docContent);
  427. $A.aAjax({
  428. url: 'docs/section/save?id=' + this.getSid(),
  429. method: 'post',
  430. data: {
  431. D: Object.assign(this.docDetail, {content: this.bakContent})
  432. },
  433. error: () => {
  434. alert(this.$L('网络繁忙,保存失败!'));
  435. },
  436. success: (res) => {
  437. if (res.ret === 1) {
  438. this.$Message.success(res.msg);
  439. this.historyNoDataText = '';
  440. } else {
  441. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  442. }
  443. }
  444. });
  445. break;
  446. case "menu":
  447. case "history":
  448. this.docDrawerTab = act;
  449. this.docDrawerShow = true
  450. break;
  451. case "share":
  452. case "view":
  453. this.$Message.info(this.$L("敬请期待!"));
  454. break;
  455. }
  456. }
  457. },
  458. }
  459. </script>