edit.vue 9.5 KB

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