edit.vue 9.6 KB

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