edit.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. <WDrawer v-model="docDrawerShow" maxWidth="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. </WDrawer>
  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. import WDrawer from "../../components/iview/WDrawer";
  170. Vue.use(minder)
  171. export default {
  172. components: {WDrawer, Flow, Sheet, TEditor, NestedDraggable},
  173. data () {
  174. return {
  175. loadIng: 0,
  176. sid: 0,
  177. hid: 0,
  178. docDetail: { },
  179. docContent: { },
  180. bakContent: null,
  181. docDrawerShow: false,
  182. docDrawerTab: '',
  183. sectionLists: [],
  184. sectionNoDataText: "",
  185. historyColumns: [],
  186. historyLists: [],
  187. historyNoDataText: "",
  188. }
  189. },
  190. created() {
  191. this.historyColumns = [{
  192. "title": this.$L("存档日期"),
  193. "minWidth": 160,
  194. "maxWidth": 200,
  195. render: (h, params) => {
  196. return h('span', $A.formatDate("Y-m-d H:i:s", params.row.indate));
  197. }
  198. }, {
  199. "title": this.$L("操作员"),
  200. "key": 'username',
  201. "minWidth": 80,
  202. "maxWidth": 130,
  203. render: (h, params) => {
  204. return h('UserView', {
  205. props: {
  206. username: params.row.username
  207. }
  208. });
  209. }
  210. }, {
  211. "title": " ",
  212. "key": 'action',
  213. "width": 80,
  214. "align": 'center',
  215. render: (h, params) => {
  216. if (this.hid == params.row.id || (this.hid == 0 && params.index == 0)) {
  217. return h('Icon', {
  218. props: { type: 'md-checkmark' },
  219. style: { marginRight: '6px', fontSize: '16px', color: '#FF5722' },
  220. });
  221. }
  222. return h('Button', {
  223. props: {
  224. type: 'text',
  225. size: 'small'
  226. },
  227. style: {
  228. fontSize: '12px'
  229. },
  230. on: {
  231. click: () => {
  232. let data = {sid: this.getSid() + "-" + params.row.id, other: this.$route.params.other}
  233. if (params.index == 0) {
  234. data.sid = this.getSid();
  235. }
  236. this.goForward({name: 'docs-edit', params: data }, true);
  237. this.refreshSid();
  238. this.docDrawerShow = false;
  239. }
  240. }
  241. }, this.$L('还原'));
  242. }
  243. }];
  244. },
  245. mounted() {
  246. },
  247. activated() {
  248. this.refreshSid();
  249. },
  250. deactivated() {
  251. this.docDrawerShow = false;
  252. if ($A.getToken() === false) {
  253. this.sid = 0;
  254. }
  255. },
  256. watch: {
  257. sid(val) {
  258. if (!val) {
  259. this.goBack();
  260. return;
  261. }
  262. this.hid = $A.runNum($A.strExists(val, '-') ? $A.getMiddle(val, "-", null) : 0);
  263. this.docDetail = { };
  264. this.docContent = { };
  265. this.bakContent = null;
  266. this.getDetail();
  267. },
  268. docDrawerTab(act) {
  269. switch (act) {
  270. case "menu":
  271. if (!this.sectionNoDataText) {
  272. this.sectionNoDataText = this.$L("数据加载中.....");
  273. let bookid = this.docDetail.bookid;
  274. $A.aAjax({
  275. url: 'docs/section/lists',
  276. data: {
  277. bookid: bookid
  278. },
  279. error: () => {
  280. if (bookid != this.docDetail.bookid) {
  281. return;
  282. }
  283. this.sectionNoDataText = this.$L("数据加载失败!");
  284. },
  285. success: (res) => {
  286. if (bookid != this.docDetail.bookid) {
  287. return;
  288. }
  289. if (res.ret === 1) {
  290. this.sectionLists = res.data;
  291. this.sectionNoDataText = this.$L("没有相关的数据");
  292. }else{
  293. this.sectionLists = [];
  294. this.sectionNoDataText = res.msg;
  295. }
  296. }
  297. });
  298. }
  299. break;
  300. case "history":
  301. if (!this.historyNoDataText) {
  302. this.historyNoDataText = this.$L("数据加载中.....");
  303. let sid = this.getSid();
  304. $A.aAjax({
  305. url: 'docs/section/history',
  306. data: {
  307. id: sid,
  308. pagesize: 50
  309. },
  310. error: () => {
  311. if (sid != this.getSid()) {
  312. return;
  313. }
  314. this.historyNoDataText = this.$L("数据加载失败!");
  315. },
  316. success: (res) => {
  317. if (sid != this.getSid()) {
  318. return;
  319. }
  320. if (res.ret === 1) {
  321. this.historyLists = res.data;
  322. this.historyNoDataText = this.$L("没有相关的数据");
  323. }else{
  324. this.historyLists = [];
  325. this.historyNoDataText = res.msg;
  326. }
  327. }
  328. });
  329. }
  330. break;
  331. }
  332. }
  333. },
  334. computed: {
  335. disabledBtn() {
  336. return this.bakContent == $A.jsonStringify(this.docContent);
  337. }
  338. },
  339. methods: {
  340. refreshSid() {
  341. this.sid = this.$route.params.sid;
  342. if (typeof this.$route.params.other === "object") {
  343. this.$set(this.docDetail, 'title', $A.getObject(this.$route.params.other, 'title'))
  344. }
  345. },
  346. getSid() {
  347. return $A.runNum($A.getMiddle(this.sid, null, '-'));
  348. },
  349. getDetail() {
  350. this.loadIng++;
  351. $A.aAjax({
  352. url: 'docs/section/content',
  353. data: {
  354. id: this.sid,
  355. },
  356. complete: () => {
  357. this.loadIng--;
  358. },
  359. error: () => {
  360. this.goBack();
  361. alert(this.$L('网络繁忙,请稍后再试!'));
  362. },
  363. success: (res) => {
  364. if (res.ret === 1) {
  365. this.docDetail = res.data;
  366. this.docContent = $A.jsonParse(res.data.content);
  367. this.bakContent = $A.jsonStringify(this.docContent);
  368. } else {
  369. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  370. this.goBack();
  371. }
  372. }
  373. });
  374. },
  375. handleSection(act, detail) {
  376. if (act === 'open') {
  377. this.goForward({name: 'docs-edit', params: {sid: detail.id, other: detail || {}}}, true);
  378. this.refreshSid();
  379. this.docDrawerShow = false;
  380. }
  381. },
  382. handleClick(act) {
  383. switch (act) {
  384. case "back":
  385. if (this.bakContent == $A.jsonStringify(this.docContent) && this.hid == 0) {
  386. this.goBack();
  387. return;
  388. }
  389. this.$Modal.confirm({
  390. title: this.$L('温馨提示'),
  391. content: this.$L('是否放弃修改的内容返回?'),
  392. loading: true,
  393. cancelText: this.$L('放弃保存'),
  394. onCancel: () => {
  395. this.goBack();
  396. },
  397. okText: this.$L('保存并返回'),
  398. onOk: () => {
  399. this.bakContent = $A.jsonStringify(this.docContent);
  400. $A.aAjax({
  401. url: 'docs/section/save?id=' + this.getSid(),
  402. method: 'post',
  403. data: {
  404. D: Object.assign(this.docDetail, {content: this.bakContent})
  405. },
  406. error: () => {
  407. this.$Modal.remove();
  408. alert(this.$L('网络繁忙,请稍后再试!'));
  409. },
  410. success: (res) => {
  411. this.$Modal.remove();
  412. this.goBack();
  413. setTimeout(() => {
  414. if (res.ret === 1) {
  415. this.$Message.success(res.msg);
  416. this.historyNoDataText = '';
  417. } else {
  418. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  419. }
  420. }, 350);
  421. }
  422. });
  423. }
  424. });
  425. break;
  426. case "save":
  427. this.bakContent = $A.jsonStringify(this.docContent);
  428. $A.aAjax({
  429. url: 'docs/section/save?id=' + this.getSid(),
  430. method: 'post',
  431. data: {
  432. D: Object.assign(this.docDetail, {content: this.bakContent})
  433. },
  434. error: () => {
  435. alert(this.$L('网络繁忙,保存失败!'));
  436. },
  437. success: (res) => {
  438. if (res.ret === 1) {
  439. this.$Message.success(res.msg);
  440. this.historyNoDataText = '';
  441. } else {
  442. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  443. }
  444. }
  445. });
  446. break;
  447. case "menu":
  448. case "history":
  449. this.docDrawerTab = act;
  450. this.docDrawerShow = true
  451. break;
  452. case "share":
  453. case "view":
  454. this.$Message.info(this.$L("敬请期待!"));
  455. break;
  456. }
  457. }
  458. },
  459. }
  460. </script>