edit.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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"><Icon type="md-share" /></div>
  9. <div class="header-menu"><Icon type="md-eye" /></div>
  10. <div class="header-menu"><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" 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" @exportData="exportMindData" :template="docContent.template" :theme="docContent.theme" :importData="docContent.root"></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. </div>
  23. </template>
  24. <style lang="scss">
  25. .docs-edit {
  26. .body-text {
  27. .teditor-loadedstyle {
  28. .tox-tinymce {
  29. border: 0;
  30. border-radius: 0;
  31. }
  32. .tox-mbtn {
  33. height: 28px;
  34. }
  35. .tox-menubar,
  36. .tox-toolbar-overlord {
  37. padding: 0 12%;
  38. background: #f9f9f9;
  39. }
  40. .tox-toolbar__primary {
  41. background: none;
  42. border-top: 1px solid #eaeaea;
  43. }
  44. .tox-toolbar-overlord {
  45. border-bottom: 1px solid #E9E9E9;
  46. }
  47. .tox-toolbar__group:not(:last-of-type) {
  48. border-right: 1px solid #eaeaea;
  49. }
  50. .tox-sidebar-wrap {
  51. margin: 22px 12%;
  52. border: 1px solid #e8e8e8;
  53. border-radius: 2px;
  54. box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.08);
  55. .tox-edit-area {
  56. border-top: 0;
  57. }
  58. }
  59. .tox-statusbar {
  60. border-top: 1px solid #E9E9E9;
  61. .tox-statusbar__resize-handle {
  62. display: none;
  63. }
  64. }
  65. }
  66. }
  67. .body-sheet {
  68. box-sizing: content-box;
  69. * {
  70. box-sizing: content-box;
  71. }
  72. }
  73. }
  74. </style>
  75. <style lang="scss" scoped>
  76. .docs-edit {
  77. .edit-box {
  78. display: flex;
  79. flex-direction: column;
  80. position: absolute;
  81. width: 100%;
  82. height: 100%;
  83. .edit-header {
  84. display: flex;
  85. flex-direction: row;
  86. align-items: center;
  87. width: 100%;
  88. height: 38px;
  89. background-color: #ffffff;
  90. box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.1);
  91. position: relative;
  92. z-index: 9;
  93. .header-menu {
  94. width: 50px;
  95. height: 100%;
  96. text-align: center;
  97. display: flex;
  98. align-items: center;
  99. justify-content: center;
  100. margin-right: 3px;
  101. cursor: pointer;
  102. color: #777777;
  103. position: relative;
  104. .ivu-icon {
  105. font-size: 16px;
  106. }
  107. &:hover,
  108. &.active {
  109. color: #fff;
  110. background: #059DFD;
  111. }
  112. }
  113. .header-title {
  114. flex: 1;
  115. color: #333333;
  116. border-left: 1px solid #ddd;
  117. margin-left: 5px;
  118. padding-left: 24px;
  119. padding-right: 24px;
  120. font-size: 16px;
  121. white-space: nowrap;
  122. }
  123. .header-hint {
  124. padding-right: 22px;
  125. font-size: 12px;
  126. color: #666;
  127. white-space: nowrap;
  128. }
  129. .header-button {
  130. font-size: 12px;
  131. margin-right: 12px;
  132. }
  133. }
  134. .docs-body {
  135. flex: 1;
  136. width: 100%;
  137. position: relative;
  138. .body-text {
  139. display: flex;
  140. width: 100%;
  141. height: 100%;
  142. .teditor-loadedstyle {
  143. height: 100%;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. </style>
  150. <script>
  151. import Vue from 'vue'
  152. import minder from '../../components/docs/minder'
  153. import TEditor from "../../components/TEditor";
  154. import Sheet from "../../components/docs/sheet/index";
  155. import Flow from "../../components/docs/flow/index";
  156. Vue.use(minder)
  157. export default {
  158. components: {Flow, Sheet, TEditor},
  159. data () {
  160. return {
  161. loadIng: 0,
  162. sid: 0,
  163. docDetail: { },
  164. docContent: { },
  165. bakContent: null,
  166. }
  167. },
  168. mounted() {
  169. },
  170. activated() {
  171. this.sid = this.$route.params.sid;
  172. if (typeof this.$route.params.other === "object") {
  173. this.$set(this.docDetail, 'title', $A.getObject(this.$route.params.other, 'title'))
  174. }
  175. },
  176. deactivated() {
  177. if ($A.getToken() === false) {
  178. this.sid = 0;
  179. }
  180. },
  181. watch: {
  182. sid(val) {
  183. if ($A.runNum(val) <= 0) {
  184. this.goBack();
  185. return;
  186. }
  187. this.docDetail = { };
  188. this.docContent = { };
  189. this.bakContent = null;
  190. this.getDetail();
  191. }
  192. },
  193. computed: {
  194. disabledBtn() {
  195. let tmpContent = $A.jsonStringify(this.docContent);
  196. return this.bakContent == tmpContent;
  197. }
  198. },
  199. methods: {
  200. getDetail() {
  201. this.loadIng++;
  202. $A.aAjax({
  203. url: 'docs/section/content',
  204. data: {
  205. id: this.sid,
  206. },
  207. complete: () => {
  208. this.loadIng--;
  209. },
  210. error: () => {
  211. this.goBack();
  212. alert(this.$L('网络繁忙,请稍后再试!'));
  213. },
  214. success: (res) => {
  215. if (res.ret === 1) {
  216. this.docDetail = res.data;
  217. this.docContent = $A.jsonParse(res.data.content);
  218. this.bakContent = $A.jsonStringify(this.docContent);
  219. } else {
  220. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  221. this.goBack();
  222. }
  223. }
  224. });
  225. },
  226. exportMindData(json) {
  227. this.docContent = json;
  228. },
  229. handleClick(act) {
  230. switch (act) {
  231. case "back":
  232. case "save":
  233. let tmpContent = $A.jsonStringify(this.docContent);
  234. if (this.bakContent != tmpContent) {
  235. this.bakContent = tmpContent;
  236. $A.aAjax({
  237. url: 'docs/section/save?id=' + this.sid,
  238. method: 'post',
  239. data: {
  240. D: Object.assign(this.docDetail, {content: tmpContent})
  241. },
  242. error: () => {
  243. alert(this.$L('网络繁忙,保存失败!'));
  244. },
  245. success: (res) => {
  246. if (res.ret === 1) {
  247. this.$Message.success(res.msg);
  248. } else {
  249. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  250. }
  251. }
  252. });
  253. }
  254. if (act == 'back') {
  255. this.goBack();
  256. }
  257. break;
  258. case "menu":
  259. break;
  260. }
  261. }
  262. },
  263. }
  264. </script>