edit.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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. <Poptip class="header-menu synch">
  12. <div class="synch-container">
  13. <Icon type="md-contacts" :title="$L('正在协作会员')"/><em v-if="synchUsers.length > 0">{{synchUsers.length}}</em>
  14. </div>
  15. <ul class="synch-lists" slot="content">
  16. <li class="title">{{$L('正在协作会员')}}:</li>
  17. <li v-for="(item, key) in synchUsersS" :key="key" @click="handleSynch(item.username)">
  18. <img class="synch-userimg" :src="item.userimg"/>
  19. <user-view class="synch-username" placement="right" :username="item.username"/>
  20. <span v-if="item.username==userInfo.username" class="synch-self">{{$L('自己')}}</span>
  21. </li>
  22. </ul>
  23. </Poptip>
  24. <div class="header-title">{{docDetail.title}}</div>
  25. <div v-if="docDetail.type=='document'" class="header-hint">
  26. <ButtonGroup size="small" shape="circle">
  27. <Button :type="`${docContent.type!='md'?'primary':'default'}`" @click="$set(docContent, 'type', 'text')">{{$L('文本编辑器')}}</Button>
  28. <Button :type="`${docContent.type=='md'?'primary':'default'}`" @click="$set(docContent, 'type', 'md')">{{$L('MD编辑器')}}</Button>
  29. </ButtonGroup>
  30. </div>
  31. <div v-else-if="docDetail.type=='mind'" class="header-hint">{{$L('选中节点,按enter键添加子节点,tab键添加同级节点')}}</div>
  32. <Button :disabled="(disabledBtn || loadIng > 0) && hid == 0" class="header-button" size="small" type="primary" @click="handleClick('save')">{{$L('保存')}}</Button>
  33. </div>
  34. <div class="docs-body">
  35. <template v-if="docDetail.type=='document'">
  36. <MDEditor v-if="docContent.type=='md'" class="body-text" v-model="docContent.content" height="100%"></MDEditor>
  37. <TEditor v-else class="body-text" v-model="docContent.content" height="100%"></TEditor>
  38. </template>
  39. <minder v-else-if="docDetail.type=='mind'" class="body-mind" v-model="docContent"></minder>
  40. <sheet v-else-if="docDetail.type=='sheet'" class="body-sheet" v-model="docContent.content"></sheet>
  41. <flow v-else-if="docDetail.type=='flow'" class="body-flow" v-model="docContent.content"></flow>
  42. </div>
  43. </div>
  44. <WDrawer v-model="docDrawerShow" maxWidth="450">
  45. <Tabs v-if="docDrawerShow" v-model="docDrawerTab">
  46. <TabPane :label="$L('知识库目录')" name="menu">
  47. <nested-draggable :lists="sectionLists" :readonly="true" :activeid="sid" @change="handleSection"></nested-draggable>
  48. <div v-if="sectionLists.length == 0" style="color:#888;padding:32px;text-align:center">{{sectionNoDataText}}</div>
  49. </TabPane>
  50. <TabPane :label="$L('文档历史版本')" name="history">
  51. <Table class="tableFill" :columns="historyColumns" :data="historyLists" :no-data-text="historyNoDataText" size="small" stripe></Table>
  52. </TabPane>
  53. </Tabs>
  54. </WDrawer>
  55. </div>
  56. </template>
  57. <style lang="scss">
  58. .docs-edit {
  59. .body-text {
  60. .mdeditor-box {
  61. position: relative;
  62. width: 100%;
  63. .markdown {
  64. position: absolute;
  65. top: 0;
  66. left: 0;
  67. bottom: 0;
  68. right: 0;
  69. overflow: auto;
  70. transform: translateZ(0);
  71. &.border {
  72. border: 0 !important;
  73. }
  74. }
  75. }
  76. .teditor-loadedstyle {
  77. .tox-tinymce {
  78. border: 0;
  79. border-radius: 0;
  80. }
  81. .tox-mbtn {
  82. height: 28px;
  83. }
  84. .tox-menubar,
  85. .tox-toolbar-overlord {
  86. padding: 0 12%;
  87. background: #f9f9f9;
  88. }
  89. .tox-toolbar__overflow,
  90. .tox-toolbar__primary {
  91. background: none !important;
  92. border-top: 1px solid #eaeaea !important;
  93. }
  94. .tox-toolbar-overlord {
  95. border-bottom: 1px solid #E9E9E9 !important;
  96. }
  97. .tox-toolbar__group:not(:last-of-type) {
  98. border-right: 1px solid #eaeaea !important;
  99. }
  100. .tox-sidebar-wrap {
  101. margin: 22px 12%;
  102. border: 1px solid #e8e8e8;
  103. border-radius: 2px;
  104. box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.08);
  105. .tox-edit-area {
  106. border-top: 0;
  107. }
  108. }
  109. .tox-statusbar {
  110. border-top: 1px solid #E9E9E9;
  111. .tox-statusbar__resize-handle {
  112. display: none;
  113. }
  114. }
  115. }
  116. }
  117. .body-sheet {
  118. box-sizing: content-box;
  119. * {
  120. box-sizing: content-box;
  121. }
  122. }
  123. }
  124. </style>
  125. <style lang="scss" scoped>
  126. .docs-edit {
  127. .edit-box {
  128. display: flex;
  129. flex-direction: column;
  130. position: absolute;
  131. width: 100%;
  132. height: 100%;
  133. .edit-header {
  134. display: flex;
  135. flex-direction: row;
  136. align-items: center;
  137. width: 100%;
  138. height: 38px;
  139. background-color: #ffffff;
  140. box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.1);
  141. position: relative;
  142. z-index: 9;
  143. .header-menu {
  144. width: 50px;
  145. height: 100%;
  146. text-align: center;
  147. display: flex;
  148. align-items: center;
  149. justify-content: center;
  150. margin-right: 3px;
  151. cursor: pointer;
  152. color: #777777;
  153. position: relative;
  154. .ivu-icon {
  155. font-size: 16px;
  156. }
  157. &.synch {
  158. .synch-container {
  159. width: 50px;
  160. height: 38px;
  161. line-height: 38px;
  162. em {
  163. padding-left: 2px;
  164. }
  165. }
  166. }
  167. &:hover,
  168. &.active {
  169. color: #fff;
  170. background: #059DFD;
  171. }
  172. .synch-lists {
  173. max-height: 500px;
  174. overflow: auto;
  175. li {
  176. display: flex;
  177. align-items: center;
  178. padding: 6px 0;
  179. border-bottom: 1px dashed #eeeeee;
  180. &.title {
  181. font-size: 14px;
  182. font-weight: 600;
  183. color: #333333;
  184. }
  185. .synch-userimg {
  186. width: 24px;
  187. height: 24px;
  188. border-radius: 50%;
  189. }
  190. .synch-self {
  191. padding: 1px 3px;
  192. margin-left: 5px;
  193. height: 18px;
  194. line-height: 16px;
  195. background-color: #FF5722;
  196. color: #ffffff;
  197. font-size: 12px;
  198. border-radius: 3px;
  199. transform: scale(0.95);
  200. }
  201. .synch-username {
  202. padding-left: 8px;
  203. font-size: 14px;
  204. color: #555555;
  205. }
  206. }
  207. }
  208. }
  209. .header-title {
  210. flex: 1;
  211. color: #333333;
  212. border-left: 1px solid #ddd;
  213. margin-left: 5px;
  214. padding-left: 24px;
  215. padding-right: 24px;
  216. font-size: 16px;
  217. white-space: nowrap;
  218. }
  219. .header-hint {
  220. padding-right: 22px;
  221. font-size: 12px;
  222. color: #666;
  223. white-space: nowrap;
  224. .ivu-btn {
  225. font-size: 12px;
  226. padding: 0 10px;
  227. }
  228. }
  229. .header-button {
  230. font-size: 12px;
  231. margin-right: 12px;
  232. }
  233. }
  234. .docs-body {
  235. flex: 1;
  236. width: 100%;
  237. position: relative;
  238. .body-text {
  239. display: flex;
  240. width: 100%;
  241. height: 100%;
  242. .teditor-loadedstyle {
  243. height: 100%;
  244. }
  245. }
  246. }
  247. }
  248. }
  249. </style>
  250. <script>
  251. import Vue from 'vue'
  252. import minder from '../../components/docs/minder'
  253. Vue.use(minder)
  254. const MDEditor = resolve => require(['../../components/MDEditor/index'], resolve);
  255. const TEditor = resolve => require(['../../components/TEditor'], resolve);
  256. const Sheet = resolve => require(['../../components/docs/sheet/index'], resolve);
  257. const Flow = resolve => require(['../../components/docs/flow/index'], resolve);
  258. const NestedDraggable = resolve => require(['../../components/docs/NestedDraggable'], resolve);
  259. const WDrawer = resolve => require(['../../components/iview/WDrawer'], resolve);
  260. export default {
  261. components: {WDrawer, Flow, Sheet, MDEditor, TEditor, NestedDraggable},
  262. data () {
  263. return {
  264. loadIng: 0,
  265. sid: 0,
  266. hid: 0,
  267. docDetail: { },
  268. docContent: { },
  269. bakContent: null,
  270. docDrawerShow: false,
  271. docDrawerTab: '',
  272. sectionLists: [],
  273. sectionNoDataText: "",
  274. historyColumns: [],
  275. historyLists: [],
  276. historyNoDataText: "",
  277. userInfo: {},
  278. routeName: '',
  279. synergyNum: 0,
  280. synchUsers: [],
  281. }
  282. },
  283. created() {
  284. this.historyColumns = [{
  285. "title": this.$L("存档日期"),
  286. "minWidth": 160,
  287. "maxWidth": 200,
  288. render: (h, params) => {
  289. return h('span', $A.formatDate("Y-m-d H:i:s", params.row.indate));
  290. }
  291. }, {
  292. "title": this.$L("操作员"),
  293. "key": 'username',
  294. "minWidth": 80,
  295. "maxWidth": 130,
  296. render: (h, params) => {
  297. return h('UserView', {
  298. props: {
  299. username: params.row.username
  300. }
  301. });
  302. }
  303. }, {
  304. "title": " ",
  305. "key": 'action',
  306. "width": 80,
  307. "align": 'center',
  308. render: (h, params) => {
  309. if (this.hid == params.row.id || (this.hid == 0 && params.index == 0)) {
  310. return h('Icon', {
  311. props: { type: 'md-checkmark' },
  312. style: { marginRight: '6px', fontSize: '16px', color: '#FF5722' },
  313. });
  314. }
  315. return h('Button', {
  316. props: {
  317. type: 'text',
  318. size: 'small'
  319. },
  320. style: {
  321. fontSize: '12px'
  322. },
  323. on: {
  324. click: () => {
  325. let data = {sid: this.getSid() + "-" + params.row.id, other: this.$route.params.other}
  326. if (params.index == 0) {
  327. data.sid = this.getSid();
  328. }
  329. this.goForward({name: 'docs-edit', params: data }, true);
  330. this.refreshSid();
  331. this.docDrawerShow = false;
  332. }
  333. }
  334. }, this.$L('还原'));
  335. }
  336. }];
  337. },
  338. mounted() {
  339. this.routeName = this.$route.name;
  340. this.userInfo = $A.getUserInfo((res, isLogin) => {
  341. if (this.userInfo.id != res.id) {
  342. this.userInfo = res;
  343. }
  344. }, false);
  345. //
  346. $A.WSOB.setOnMsgListener("chat/index", ['docs'], (msgDetail) => {
  347. if (this.routeName !== this.$route.name) {
  348. return;
  349. }
  350. let body = msgDetail.body;
  351. if (body.sid != this.sid) {
  352. return;
  353. }
  354. if (body.type === 'users') {
  355. this.synchUsers = body.lists;
  356. this.synchUsers.splice(this.synchUsers.length);
  357. } else if (body.type === 'update') {
  358. this.$Modal.confirm({
  359. title: this.$L("更新提示"),
  360. content: this.$L('团队成员(%)更新了内容,<br/>更新时间:%。<br/><br/>点击【确定】加载最新内容。', body.nickname, $A.formatDate("Y-m-d H:i:s", body.time)),
  361. onOk: () => {
  362. this.refreshDetail();
  363. }
  364. });
  365. }
  366. });
  367. },
  368. activated() {
  369. this.refreshSid();
  370. this.synergy(true);
  371. },
  372. deactivated() {
  373. this.synergy(false);
  374. this.docDrawerShow = false;
  375. if ($A.getToken() === false) {
  376. this.sid = 0;
  377. }
  378. },
  379. watch: {
  380. sid(val) {
  381. if (!val) {
  382. this.goBack();
  383. return;
  384. }
  385. this.hid = $A.runNum($A.strExists(val, '-') ? $A.getMiddle(val, "-", null) : 0);
  386. this.refreshDetail();
  387. },
  388. docDrawerTab(act) {
  389. switch (act) {
  390. case "menu":
  391. if (!this.sectionNoDataText) {
  392. this.sectionNoDataText = this.$L("数据加载中.....");
  393. let bookid = this.docDetail.bookid;
  394. $A.aAjax({
  395. url: 'docs/section/lists',
  396. data: {
  397. bookid: bookid
  398. },
  399. error: () => {
  400. if (bookid != this.docDetail.bookid) {
  401. return;
  402. }
  403. this.sectionNoDataText = this.$L("数据加载失败!");
  404. },
  405. success: (res) => {
  406. if (bookid != this.docDetail.bookid) {
  407. return;
  408. }
  409. if (res.ret === 1) {
  410. this.sectionLists = res.data;
  411. this.sectionNoDataText = this.$L("没有相关的数据");
  412. }else{
  413. this.sectionLists = [];
  414. this.sectionNoDataText = res.msg;
  415. }
  416. }
  417. });
  418. }
  419. break;
  420. case "history":
  421. if (!this.historyNoDataText) {
  422. this.historyNoDataText = this.$L("数据加载中.....");
  423. let sid = this.getSid();
  424. $A.aAjax({
  425. url: 'docs/section/history',
  426. data: {
  427. id: sid,
  428. pagesize: 50
  429. },
  430. error: () => {
  431. if (sid != this.getSid()) {
  432. return;
  433. }
  434. this.historyNoDataText = this.$L("数据加载失败!");
  435. },
  436. success: (res) => {
  437. if (sid != this.getSid()) {
  438. return;
  439. }
  440. if (res.ret === 1) {
  441. this.historyLists = res.data;
  442. this.historyNoDataText = this.$L("没有相关的数据");
  443. }else{
  444. this.historyLists = [];
  445. this.historyNoDataText = res.msg;
  446. }
  447. }
  448. });
  449. }
  450. break;
  451. }
  452. }
  453. },
  454. computed: {
  455. disabledBtn() {
  456. return this.bakContent == $A.jsonStringify(this.docContent);
  457. },
  458. synchUsersS() {
  459. let temp = Math.round(new Date().getTime() / 1000);
  460. return this.synchUsers.filter(item => {
  461. return item.indate + 10 > temp;
  462. });
  463. }
  464. },
  465. methods: {
  466. synergy(enter) {
  467. if (enter === false) {
  468. $A.WSOB.sendTo('docs', {
  469. type: 'quit',
  470. sid: this.sid,
  471. username: this.userInfo.username,
  472. });
  473. } else {
  474. if (this.routeName !== this.$route.name) {
  475. let tmpNum = this.synergyNum;
  476. setTimeout(() => {
  477. if (tmpNum === this.synergyNum) {
  478. this.synergyNum++;
  479. this.synergy();
  480. }
  481. }, 10000);
  482. } else {
  483. $A.WSOB.sendTo('docs', null, {
  484. type: enter === true ? 'enter' : 'refresh',
  485. sid: this.sid,
  486. username: this.userInfo.username,
  487. userimg: this.userInfo.userimg,
  488. indate: Math.round(new Date().getTime() / 1000),
  489. }, (res) => {
  490. this.synchUsers = res.status === 1 ? res.message : [];
  491. let tmpNum = this.synergyNum;
  492. setTimeout(() => {
  493. if (tmpNum === this.synergyNum) {
  494. this.synergyNum++;
  495. this.synergy();
  496. }
  497. }, 10000);
  498. });
  499. }
  500. }
  501. },
  502. refreshSid() {
  503. this.sid = this.$route.params.sid;
  504. if (typeof this.$route.params.other === "object") {
  505. this.$set(this.docDetail, 'title', $A.getObject(this.$route.params.other, 'title'))
  506. }
  507. },
  508. getSid() {
  509. return $A.runNum($A.getMiddle(this.sid, null, '-'));
  510. },
  511. refreshDetail() {
  512. this.docDetail = { };
  513. this.docContent = { };
  514. this.bakContent = null;
  515. this.getDetail();
  516. },
  517. getDetail() {
  518. this.loadIng++;
  519. $A.aAjax({
  520. url: 'docs/section/content',
  521. data: {
  522. id: this.sid,
  523. },
  524. complete: () => {
  525. this.loadIng--;
  526. },
  527. error: () => {
  528. this.goBack();
  529. alert(this.$L('网络繁忙,请稍后再试!'));
  530. },
  531. success: (res) => {
  532. if (res.ret === 1) {
  533. this.docDetail = res.data;
  534. this.docContent = $A.jsonParse(res.data.content);
  535. this.bakContent = $A.jsonStringify(this.docContent);
  536. } else {
  537. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  538. this.goBack();
  539. }
  540. }
  541. });
  542. },
  543. handleSection(act, detail) {
  544. if (act === 'open') {
  545. this.goForward({name: 'docs-edit', params: {sid: detail.id, other: detail || {}}}, true);
  546. this.refreshSid();
  547. this.docDrawerShow = false;
  548. }
  549. },
  550. handleSynch(username) {
  551. if (username == this.userInfo.username) {
  552. return;
  553. }
  554. if (typeof window.onChatOpenUserName === "function") {
  555. window.onChatOpenUserName(username);
  556. }
  557. },
  558. handleClick(act) {
  559. switch (act) {
  560. case "back":
  561. if (this.bakContent == $A.jsonStringify(this.docContent) && this.hid == 0) {
  562. this.goBack();
  563. return;
  564. }
  565. this.$Modal.confirm({
  566. title: this.$L('温馨提示'),
  567. content: this.$L('是否放弃修改的内容返回?'),
  568. loading: true,
  569. cancelText: this.$L('放弃保存'),
  570. onCancel: () => {
  571. this.goBack();
  572. },
  573. okText: this.$L('保存并返回'),
  574. onOk: () => {
  575. this.bakContent = $A.jsonStringify(this.docContent);
  576. $A.aAjax({
  577. url: 'docs/section/save?id=' + this.getSid(),
  578. method: 'post',
  579. data: {
  580. D: Object.assign(this.docDetail, {content: this.bakContent})
  581. },
  582. error: () => {
  583. this.$Modal.remove();
  584. alert(this.$L('网络繁忙,请稍后再试!'));
  585. },
  586. success: (res) => {
  587. this.$Modal.remove();
  588. this.goBack();
  589. setTimeout(() => {
  590. if (res.ret === 1) {
  591. this.$Message.success(res.msg);
  592. this.historyNoDataText = '';
  593. } else {
  594. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  595. }
  596. }, 350);
  597. }
  598. });
  599. }
  600. });
  601. break;
  602. case "save":
  603. this.bakContent = $A.jsonStringify(this.docContent);
  604. $A.aAjax({
  605. url: 'docs/section/save?id=' + this.getSid(),
  606. method: 'post',
  607. data: {
  608. D: Object.assign(this.docDetail, {content: this.bakContent})
  609. },
  610. error: () => {
  611. alert(this.$L('网络繁忙,保存失败!'));
  612. },
  613. success: (res) => {
  614. if (res.ret === 1) {
  615. this.$Message.success(res.msg);
  616. this.historyNoDataText = '';
  617. } else {
  618. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  619. }
  620. }
  621. });
  622. break;
  623. case "menu":
  624. case "history":
  625. this.docDrawerTab = act;
  626. this.docDrawerShow = true
  627. break;
  628. case "share":
  629. case "view":
  630. this.$Message.info(this.$L("敬请期待!"));
  631. break;
  632. }
  633. }
  634. },
  635. }
  636. </script>