edit.vue 19 KB

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