edit.vue 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  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. <Tooltip class="header-menu" :content="$L('知识库目录')">
  8. <div class="menu-container" @click="handleClick('menu')"><Icon type="md-menu" /></div>
  9. </Tooltip>
  10. <Tooltip class="header-menu" :content="$L('分享文档')">
  11. <div class="menu-container" @click="handleClick('share')"><Icon type="md-share" /></div>
  12. </Tooltip>
  13. <Tooltip class="header-menu" :content="$L('浏览文档')">
  14. <a class="menu-container" target="_blank" :href="handleClick('view')"><Icon type="md-eye" /></a>
  15. </Tooltip>
  16. <Tooltip class="header-menu" :content="$L('历史版本')">
  17. <div class="menu-container" @click="handleClick('history')"><Icon type="md-time" /></div>
  18. </Tooltip>
  19. <Poptip class="header-menu synch">
  20. <div class="menu-container">
  21. <Icon type="md-contacts" :title="$L('正在协作会员')"/><em v-if="synchUsers.length > 0">{{synchUsers.length}}</em>
  22. </div>
  23. <ul class="synch-lists" slot="content">
  24. <li class="title">{{$L('正在协作会员')}}:</li>
  25. <li v-for="(item, key) in synchUsersS" :key="key" @click="handleSynch(item.username)">
  26. <UserView class="synch-username" placement="right" :username="item.username" showimg/>
  27. <span v-if="item.username==userInfo.username" class="synch-self">{{$L('自己')}}</span>
  28. </li>
  29. </ul>
  30. </Poptip>
  31. <Tooltip class="header-menu" :class="{lock:isLock}" max-width="500">
  32. <div slot="content" style="white-space:nowrap">
  33. <span v-if="isLock&&docDetail.lockname!=userInfo.username">【<UserView :username="docDetail.lockname"/>】{{$L('已锁定')}}</span>
  34. <span v-else>{{$L('锁定后其他会员将无法修改保存文档。')}}</span>
  35. </div>
  36. <div class="menu-container" @click="handleClick(isLock?'unlock':'lock')"><Icon :type="isLock?'md-lock':'md-unlock'" /></div>
  37. </Tooltip>
  38. <div class="header-title">{{docDetail.title}}</div>
  39. <div v-if="docDetail.type=='document'" class="header-hint">
  40. <ButtonGroup size="small" shape="circle">
  41. <Button :type="`${docContent.type!='md'?'primary':'default'}`" @click="$set(docContent, 'type', 'text')">{{$L('文本编辑器')}}</Button>
  42. <Button :type="`${docContent.type=='md'?'primary':'default'}`" @click="$set(docContent, 'type', 'md')">{{$L('MD编辑器')}}</Button>
  43. </ButtonGroup>
  44. </div>
  45. <div v-if="docDetail.type=='mind'" class="header-hint">
  46. {{$L('选中节点,按enter键添加同级节点,tab键添加子节点')}}
  47. </div>
  48. <Dropdown v-if="docDetail.type=='mind' || docDetail.type=='flow' || docDetail.type=='sheet'"
  49. trigger="click"
  50. class="header-hint"
  51. @on-click="exportMenu">
  52. <a href="javascript:void(0)">
  53. {{$L('导出')}}
  54. <Icon type="ios-arrow-down"></Icon>
  55. </a>
  56. <DropdownMenu v-if="docDetail.type=='sheet'" slot="list">
  57. <DropdownItem name="xlsx">{{$L('导出XLSX')}}</DropdownItem>
  58. <DropdownItem name="xlml">{{$L('导出XLS')}}</DropdownItem>
  59. <DropdownItem name="csv">{{$L('导出CSV')}}</DropdownItem>
  60. <DropdownItem name="txt">{{$L('导出TXT')}}</DropdownItem>
  61. </DropdownMenu>
  62. <DropdownMenu v-else slot="list">
  63. <DropdownItem name="png">{{$L('导出PNG图片')}}</DropdownItem>
  64. <DropdownItem name="pdf">{{$L('导出PDF文件')}}</DropdownItem>
  65. </DropdownMenu>
  66. </Dropdown>
  67. <Button :disabled="equalContent" :loading="loadIng > 0" class="header-button" size="small" type="primary" @click="handleClick('save')">{{$L('保存')}}</Button>
  68. </div>
  69. <div class="docs-body">
  70. <template v-if="docDetail.type=='document'">
  71. <MDEditor v-if="docContent.type=='md'" class="body-text" v-model="docContent.content" height="100%"></MDEditor>
  72. <TEditor v-else class="body-text" v-model="docContent.content" height="100%" @editorSave="handleClick('saveBefore')"></TEditor>
  73. </template>
  74. <minder v-else-if="docDetail.type=='mind'" ref="myMind" class="body-mind" v-model="docContent" @saveData="handleClick('saveBefore')"></minder>
  75. <sheet v-else-if="docDetail.type=='sheet'" ref="mySheet" class="body-sheet" v-model="docContent.content"></sheet>
  76. <flow v-else-if="docDetail.type=='flow'" ref="myFlow" class="body-flow" v-model="docContent.content" @saveData="handleClick('saveBefore')"></flow>
  77. </div>
  78. </div>
  79. <WDrawer v-model="docDrawerShow" maxWidth="450">
  80. <Tabs v-if="docDrawerShow" v-model="docDrawerTab">
  81. <TabPane :label="$L('知识库目录')" name="menu">
  82. <nested-draggable :lists="sectionLists" :readonly="true" :activeid="sid" @change="handleSection"></nested-draggable>
  83. <div v-if="sectionLists.length == 0" style="color:#888;padding:32px;text-align:center">{{sectionNoDataText}}</div>
  84. </TabPane>
  85. <TabPane :label="$L('文档历史版本')" name="history">
  86. <Table class="tableFill" :columns="historyColumns" :data="historyLists" :no-data-text="historyNoDataText" size="small" stripe></Table>
  87. </TabPane>
  88. </Tabs>
  89. </WDrawer>
  90. </div>
  91. </template>
  92. <style lang="scss">
  93. .docs-edit {
  94. .edit-box {
  95. .synch-username {
  96. .user-view-img {
  97. width: 24px;
  98. height: 24px;
  99. font-size: 14px;
  100. line-height: 24px;
  101. border-radius: 12px;
  102. }
  103. }
  104. }
  105. .body-text {
  106. .mdeditor-box {
  107. position: relative;
  108. width: 100%;
  109. .markdown {
  110. position: absolute;
  111. top: 0;
  112. left: 0;
  113. bottom: 0;
  114. right: 0;
  115. overflow: auto;
  116. transform: translateZ(0);
  117. &.border {
  118. border: 0 !important;
  119. }
  120. }
  121. }
  122. .teditor-loadedstyle {
  123. .tox-tinymce {
  124. border: 0;
  125. border-radius: 0;
  126. }
  127. .tox-mbtn {
  128. height: 28px;
  129. }
  130. .tox-menubar,
  131. .tox-toolbar-overlord {
  132. padding: 0 12%;
  133. background: #f9f9f9;
  134. }
  135. .tox-toolbar__overflow,
  136. .tox-toolbar__primary {
  137. background: none !important;
  138. border-top: 1px solid #eaeaea !important;
  139. }
  140. .tox-toolbar-overlord {
  141. border-bottom: 1px solid #E9E9E9 !important;
  142. }
  143. .tox-toolbar__group:not(:last-of-type) {
  144. border-right: 1px solid #eaeaea !important;
  145. }
  146. .tox-sidebar-wrap {
  147. margin: 22px 12%;
  148. border: 1px solid #e8e8e8;
  149. border-radius: 2px;
  150. box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.08);
  151. .tox-edit-area {
  152. border-top: 0;
  153. }
  154. }
  155. .tox-statusbar {
  156. border-top: 1px solid #E9E9E9;
  157. .tox-statusbar__resize-handle {
  158. display: none;
  159. }
  160. }
  161. }
  162. }
  163. .body-sheet {
  164. box-sizing: content-box;
  165. * {
  166. box-sizing: content-box;
  167. }
  168. }
  169. }
  170. </style>
  171. <style lang="scss" scoped>
  172. .docs-edit {
  173. .edit-box {
  174. display: flex;
  175. flex-direction: column;
  176. position: absolute;
  177. width: 100%;
  178. height: 100%;
  179. overflow-x: auto;
  180. .edit-header {
  181. display: flex;
  182. flex-direction: row;
  183. align-items: center;
  184. width: 100%;
  185. height: 38px;
  186. min-width: 1024px;
  187. background-color: #ffffff;
  188. box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.1);
  189. position: relative;
  190. z-index: 99;
  191. .header-menu {
  192. width: 48px;
  193. height: 100%;
  194. text-align: center;
  195. display: flex;
  196. align-items: center;
  197. justify-content: center;
  198. margin-right: 3px;
  199. cursor: pointer;
  200. position: relative;
  201. .menu-container {
  202. display: inline-block;
  203. width: 48px;
  204. height: 38px;
  205. line-height: 38px;
  206. color: #777777;
  207. transition: color .2s ease;
  208. }
  209. .ivu-icon {
  210. font-size: 16px;
  211. }
  212. &.synch {
  213. .menu-container {
  214. em {
  215. padding-left: 2px;
  216. }
  217. }
  218. }
  219. &.lock {
  220. .menu-container {
  221. color: #059DFD;
  222. }
  223. }
  224. &:hover,
  225. &.active {
  226. color: #fff;
  227. background: #059DFD;
  228. .menu-container {
  229. color: #fff;
  230. }
  231. }
  232. .synch-lists {
  233. max-height: 500px;
  234. overflow: auto;
  235. li {
  236. display: flex;
  237. align-items: center;
  238. padding: 6px 0;
  239. border-bottom: 1px dashed #eeeeee;
  240. &.title {
  241. font-size: 14px;
  242. font-weight: 600;
  243. color: #333333;
  244. }
  245. .synch-userimg {
  246. width: 24px;
  247. height: 24px;
  248. font-size: 14px;
  249. line-height: 24px;
  250. border-radius: 12px;
  251. }
  252. .synch-self {
  253. padding: 1px 3px;
  254. margin-left: 5px;
  255. height: 18px;
  256. line-height: 16px;
  257. background-color: #FF5722;
  258. color: #ffffff;
  259. font-size: 12px;
  260. border-radius: 3px;
  261. transform: scale(0.95);
  262. }
  263. .synch-username {
  264. padding-left: 8px;
  265. font-size: 14px;
  266. color: #555555;
  267. }
  268. }
  269. }
  270. }
  271. .header-title {
  272. flex: 1;
  273. color: #333333;
  274. border-left: 1px solid #ddd;
  275. margin-left: 5px;
  276. padding-left: 24px;
  277. padding-right: 24px;
  278. font-size: 16px;
  279. overflow: hidden;
  280. text-overflow:ellipsis;
  281. white-space: nowrap;
  282. }
  283. .header-hint {
  284. padding-right: 22px;
  285. font-size: 12px;
  286. color: #666;
  287. white-space: nowrap;
  288. .ivu-btn {
  289. font-size: 12px;
  290. padding: 0 10px;
  291. }
  292. .ivu-dropdown-item {
  293. font-size: 12px !important;
  294. }
  295. }
  296. .header-button {
  297. font-size: 12px;
  298. margin-right: 12px;
  299. }
  300. }
  301. .docs-body {
  302. flex: 1;
  303. width: 100%;
  304. min-width: 1024px;
  305. position: relative;
  306. .body-text {
  307. display: flex;
  308. width: 100%;
  309. height: 100%;
  310. .teditor-loadedstyle {
  311. height: 100%;
  312. }
  313. }
  314. }
  315. }
  316. }
  317. </style>
  318. <script>
  319. import Vue from 'vue'
  320. import minder from '../../components/docs/minder'
  321. Vue.use(minder)
  322. const MDEditor = resolve => require(['../../components/MDEditor/index'], resolve);
  323. const TEditor = resolve => require(['../../components/TEditor'], resolve);
  324. const Sheet = resolve => require(['../../components/docs/sheet/index'], resolve);
  325. const Flow = resolve => require(['../../components/docs/flow/index'], resolve);
  326. const NestedDraggable = resolve => require(['../../components/docs/NestedDraggable'], resolve);
  327. const WDrawer = resolve => require(['../../components/iview/WDrawer'], resolve);
  328. export default {
  329. components: {WDrawer, Flow, Sheet, MDEditor, TEditor, NestedDraggable},
  330. data () {
  331. return {
  332. loadIng: 0,
  333. sid: 0,
  334. hid: 0,
  335. docDetail: { },
  336. docContent: { },
  337. bakContent: null,
  338. docDrawerShow: false,
  339. docDrawerTab: '',
  340. sectionLists: [],
  341. sectionNoDataText: "",
  342. historyColumns: [],
  343. historyLists: [],
  344. historyNoDataText: "",
  345. routeName: '',
  346. synergyNum: 0,
  347. synchUsers: [],
  348. timeValue: Math.round(new Date().getTime() / 1000),
  349. }
  350. },
  351. created() {
  352. this.historyColumns = [{
  353. "title": this.$L("存档日期"),
  354. "minWidth": 160,
  355. "maxWidth": 200,
  356. render: (h, params) => {
  357. return h('span', $A.formatDate("Y-m-d H:i:s", params.row.indate));
  358. }
  359. }, {
  360. "title": this.$L("操作员"),
  361. "key": 'username',
  362. "minWidth": 80,
  363. "maxWidth": 130,
  364. render: (h, params) => {
  365. return h('UserView', {
  366. props: {
  367. username: params.row.username
  368. }
  369. });
  370. }
  371. }, {
  372. "title": " ",
  373. "key": 'action',
  374. "width": 80,
  375. "align": 'center',
  376. render: (h, params) => {
  377. if (this.hid == params.row.id || (this.hid == 0 && params.index == 0)) {
  378. return h('Icon', {
  379. props: { type: 'md-checkmark' },
  380. style: { marginRight: '6px', fontSize: '16px', color: '#FF5722' },
  381. });
  382. }
  383. return h('Button', {
  384. props: {
  385. type: 'text',
  386. size: 'small'
  387. },
  388. style: {
  389. fontSize: '12px'
  390. },
  391. on: {
  392. click: () => {
  393. let data = {sid: this.getSid() + "-" + params.row.id, other: this.$route.params.other}
  394. if (params.index == 0) {
  395. data.sid = this.getSid();
  396. }
  397. this.handleSection('openBefore', data);
  398. }
  399. }
  400. }, this.$L('还原'));
  401. }
  402. }];
  403. },
  404. mounted() {
  405. this.routeName = this.$route.name;
  406. //
  407. setInterval(() => {
  408. if (this.routeName === this.$route.name) {
  409. this.timeValue = Math.round(new Date().getTime() / 1000);
  410. }
  411. });
  412. //
  413. $(window).bind('beforeunload', () => {
  414. if (!this.equalContent && this.routeName === this.$route.name) {
  415. return '是否放弃修改的内容返回?';
  416. }
  417. });
  418. //
  419. $A.WSOB.setOnMsgListener("chat/index", ['docs'], (msgDetail) => {
  420. if (this.routeName !== this.$route.name) {
  421. return;
  422. }
  423. let body = msgDetail.body;
  424. if (body.sid != this.sid) {
  425. return;
  426. }
  427. switch (body.type) {
  428. case 'users':
  429. this.synchUsers = body.lists;
  430. this.synchUsers.splice(this.synchUsers.length);
  431. break;
  432. case 'update':
  433. this.$Modal.confirm({
  434. title: this.$L("更新提示"),
  435. content: this.$L('团队成员(%)更新了内容,<br/>更新时间:%。<br/><br/>点击【确定】加载最新内容。', body.nickname, $A.formatDate("Y-m-d H:i:s", body.time)),
  436. onOk: () => {
  437. this.refreshDetail();
  438. }
  439. });
  440. break;
  441. case 'lock':
  442. case 'unlock':
  443. if (this.docDetail.lockname == body.lockname) {
  444. return;
  445. }
  446. this.$set(this.docDetail, 'lockname', body.lockname);
  447. this.$set(this.docDetail, 'lockdate', body.lockdate);
  448. this.$Notice.close('docs-lock')
  449. this.$Notice[body.type=='lock'?'warning':'info']({
  450. name: 'docs-lock',
  451. duration: 0,
  452. render: h => {
  453. return h('div', {
  454. style: {
  455. lineHeight: '18px'
  456. }
  457. }, [
  458. h('span', {
  459. style: {
  460. fontWeight: 500
  461. }
  462. }, body.nickname + ':'),
  463. h('span', {
  464. style: {
  465. paddingLeft: '6px'
  466. }
  467. }, this.$L(body.type == 'lock' ? '锁定文档' : '解锁文档'))
  468. ])
  469. }
  470. });
  471. break;
  472. }
  473. });
  474. },
  475. activated() {
  476. this.docDrawerTab = '';
  477. this.sectionNoDataText = '';
  478. this.historyNoDataText = '';
  479. //
  480. this.refreshSid();
  481. this.synergy(true);
  482. document.addEventListener("keydown", this.keySave);
  483. },
  484. deactivated() {
  485. if (this.isLock && this.docDetail.lockname == this.usrInfo.username) {
  486. this.docDetail.lockname = '';
  487. this.handleClick('unlock');
  488. }
  489. this.$Notice.close('docs-lock');
  490. //
  491. if (!this.equalContent) {
  492. this.handleClick('save');
  493. }
  494. //
  495. this.synergy(false);
  496. document.removeEventListener("keydown", this.keySave);
  497. this.docDrawerShow = false;
  498. if ($A.getToken() === false) {
  499. this.sid = 0;
  500. }
  501. },
  502. watch: {
  503. sid(val) {
  504. if (!val) {
  505. this.goBackDirect();
  506. return;
  507. }
  508. this.hid = $A.runNum($A.strExists(val, '-') ? $A.getMiddle(val, "-", null) : 0);
  509. this.refreshDetail();
  510. },
  511. '$route' (To) {
  512. if (To.name == 'docs-edit') {
  513. this.sid = To.params.sid;
  514. }
  515. },
  516. docDrawerTab(act) {
  517. switch (act) {
  518. case "menu":
  519. if (!this.sectionNoDataText) {
  520. this.sectionNoDataText = this.$L("数据加载中.....");
  521. let bookid = this.docDetail.bookid;
  522. $A.apiAjax({
  523. url: 'docs/section/lists',
  524. data: {
  525. act: 'edit',
  526. bookid: bookid
  527. },
  528. error: () => {
  529. if (bookid != this.docDetail.bookid) {
  530. return;
  531. }
  532. this.sectionNoDataText = this.$L("数据加载失败!");
  533. },
  534. success: (res) => {
  535. if (bookid != this.docDetail.bookid) {
  536. return;
  537. }
  538. if (res.ret === 1) {
  539. this.sectionLists = res.data.tree;
  540. this.sectionNoDataText = this.$L("没有相关的数据");
  541. }else{
  542. this.sectionLists = [];
  543. this.sectionNoDataText = res.msg;
  544. }
  545. }
  546. });
  547. }
  548. break;
  549. case "history":
  550. if (!this.historyNoDataText) {
  551. this.historyNoDataText = this.$L("数据加载中.....");
  552. let sid = this.getSid();
  553. $A.apiAjax({
  554. url: 'docs/section/history',
  555. data: {
  556. id: sid,
  557. pagesize: 50
  558. },
  559. error: () => {
  560. if (sid != this.getSid()) {
  561. return;
  562. }
  563. this.historyNoDataText = this.$L("数据加载失败!");
  564. },
  565. success: (res) => {
  566. if (sid != this.getSid()) {
  567. return;
  568. }
  569. if (res.ret === 1) {
  570. this.historyLists = res.data;
  571. this.historyNoDataText = this.$L("没有相关的数据");
  572. }else{
  573. this.historyLists = [];
  574. this.historyNoDataText = res.msg;
  575. }
  576. }
  577. });
  578. }
  579. break;
  580. }
  581. }
  582. },
  583. computed: {
  584. equalContent() {
  585. return this.bakContent == $A.jsonStringify(this.docContent);
  586. },
  587. synchUsersS() {
  588. return this.synchUsers.filter(item => {
  589. return item.indate + 20 > this.timeValue;
  590. });
  591. },
  592. isLock() {
  593. return !!(this.docDetail.lockname && this.docDetail.lockdate > this.timeValue - 60);
  594. }
  595. },
  596. methods: {
  597. keySave(e) {
  598. if ((e.ctrlKey || e.metaKey) && e.keyCode === 83) {
  599. this.handleClick('saveBefore');
  600. e.preventDefault();
  601. }
  602. },
  603. goBackDirect() {
  604. this.bakContent = $A.jsonStringify(this.docContent);
  605. this.goBack({name:'docs'});
  606. },
  607. synergy(enter) {
  608. if (enter === false) {
  609. $A.WSOB.sendTo('docs', {
  610. type: 'quit',
  611. sid: this.sid,
  612. username: this.usrInfo.username,
  613. });
  614. } else {
  615. if (this.routeName !== this.$route.name) {
  616. let tmpNum = this.synergyNum;
  617. setTimeout(() => {
  618. if (tmpNum === this.synergyNum) {
  619. this.synergyNum++;
  620. this.synergy();
  621. }
  622. }, 10000);
  623. } else {
  624. $A.WSOB.sendTo('docs', null, {
  625. type: enter === true ? 'enter' : 'refresh',
  626. sid: this.sid,
  627. nickname: this.usrInfo.nickname,
  628. username: this.usrInfo.username,
  629. userimg: this.usrInfo.userimg,
  630. indate: Math.round(new Date().getTime() / 1000),
  631. }, (res) => {
  632. this.synchUsers = res.status === 1 ? res.message : [];
  633. let tmpNum = this.synergyNum;
  634. setTimeout(() => {
  635. if (tmpNum === this.synergyNum) {
  636. this.synergyNum++;
  637. this.synergy();
  638. }
  639. }, 10000);
  640. });
  641. }
  642. }
  643. },
  644. refreshSid() {
  645. this.sid = this.$route.params.sid;
  646. if (typeof this.$route.params.other === "object") {
  647. this.$set(this.docDetail, 'title', $A.getObject(this.$route.params.other, 'title'))
  648. }
  649. },
  650. getSid() {
  651. return $A.runNum($A.getMiddle(this.sid, null, '-'));
  652. },
  653. refreshDetail() {
  654. this.docDetail = { };
  655. this.docContent = { };
  656. this.bakContent = null;
  657. this.getDetail();
  658. },
  659. getDetail() {
  660. this.loadIng++;
  661. $A.apiAjax({
  662. url: 'docs/section/content',
  663. data: {
  664. act: 'edit',
  665. id: this.sid,
  666. },
  667. complete: () => {
  668. this.loadIng--;
  669. },
  670. error: () => {
  671. this.goBackDirect();
  672. alert(this.$L('网络繁忙,请稍后再试!'));
  673. },
  674. success: (res) => {
  675. if (res.ret === 1) {
  676. this.docDetail = res.data;
  677. this.docContent = $A.jsonParse(res.data.content);
  678. this.bakContent = this.hid == 0 ? $A.jsonStringify(this.docContent) : '';
  679. this.continueLock(1000);
  680. } else {
  681. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  682. }
  683. }
  684. });
  685. },
  686. handleSection(act, detail) {
  687. switch (act) {
  688. case 'open':
  689. this.handleSection('openBefore', {sid: detail.id, other: detail || {}})
  690. break;
  691. case 'openBefore':
  692. if (!this.equalContent) {
  693. this.$Modal.confirm({
  694. title: this.$L('温馨提示'),
  695. content: this.$L('是否放弃保存修改的内容?'),
  696. cancelText: this.$L('取消'),
  697. okText: this.$L('放弃保存'),
  698. onOk: () => {
  699. this.handleSection('openConfirm', detail)
  700. }
  701. });
  702. } else {
  703. this.handleSection('openConfirm', detail)
  704. }
  705. break;
  706. case 'openConfirm':
  707. this.goForward({name: 'docs-edit', params: detail}, true);
  708. this.refreshSid();
  709. this.docDrawerShow = false;
  710. break;
  711. }
  712. },
  713. handleSynch(username) {
  714. if (username == this.usrInfo.username) {
  715. return;
  716. }
  717. if (typeof window.onChatOpenUserName === "function") {
  718. window.onChatOpenUserName(username);
  719. }
  720. },
  721. handleClick(act) {
  722. switch (act) {
  723. case "back":
  724. if (this.equalContent) {
  725. this.goBackDirect();
  726. return;
  727. }
  728. this.$Modal.confirm({
  729. title: this.$L('温馨提示'),
  730. content: this.$L('是否放弃修改的内容返回?'),
  731. cancelText: this.$L('放弃保存'),
  732. onCancel: () => {
  733. this.goBackDirect();
  734. },
  735. okText: this.$L('保存并返回'),
  736. onOk: () => {
  737. this.handleClick('save');
  738. this.goBackDirect();
  739. }
  740. });
  741. break;
  742. case "saveBefore":
  743. if (!this.equalContent && this.loadIng == 0) {
  744. this.handleClick('save');
  745. } else {
  746. this.$Message.warning(this.$L('没有任何修改!'));
  747. }
  748. return;
  749. case "save":
  750. this.bakContent = $A.jsonStringify(this.docContent);
  751. $A.apiAjax({
  752. url: 'docs/section/save',
  753. method: 'post',
  754. data: Object.assign(this.docDetail, {
  755. id: this.getSid(),
  756. content: this.bakContent
  757. }),
  758. error: () => {
  759. this.bakContent = '';
  760. alert(this.$L('网络繁忙,保存失败!'));
  761. },
  762. success: (res) => {
  763. if (res.ret === 1) {
  764. if (this.getSid() == res.data.sid) {
  765. this.docContent = Object.assign({}, this.docContent, res.data.content);
  766. }
  767. this.$Message.success(res.msg);
  768. this.historyNoDataText = '';
  769. if (this.hid != 0) {
  770. this.hid = 0;
  771. this.goForward({name: 'docs-edit', params: {sid: this.getSid()}}, true);
  772. }
  773. } else {
  774. this.bakContent = '';
  775. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  776. }
  777. }
  778. });
  779. break;
  780. case "menu":
  781. case "history":
  782. this.docDrawerTab = act;
  783. this.docDrawerShow = true
  784. break;
  785. case "share":
  786. this.$Modal.confirm({
  787. render: (h) => {
  788. return h('div', [
  789. h('div', {
  790. style: {
  791. fontSize: '16px',
  792. fontWeight: '500',
  793. marginBottom: '20px',
  794. }
  795. }, this.$L('文档链接')),
  796. h('Input', {
  797. props: {
  798. value: this.handleClick('view'),
  799. readonly: true,
  800. },
  801. })
  802. ])
  803. },
  804. });
  805. break;
  806. case "lock":
  807. case "unlock":
  808. $A.apiAjax({
  809. url: 'docs/section/lock?id=' + this.getSid(),
  810. data: {
  811. act: act,
  812. },
  813. error: () => {
  814. alert(this.$L('网络繁忙,请稍后再试!'));
  815. },
  816. success: (res) => {
  817. if (res.ret === 1) {
  818. if (this.docDetail.lockname != res.data.lockname) {
  819. this.$Message.success(res.msg);
  820. }
  821. this.$set(this.docDetail, 'lockname', res.data.lockname);
  822. this.$set(this.docDetail, 'lockdate', res.data.lockdate);
  823. this.continueLock(20000);
  824. } else {
  825. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  826. }
  827. }
  828. });
  829. break;
  830. case "view":
  831. return $A.webUrl('docs/view/' + this.docDetail.id);
  832. }
  833. },
  834. continueLock(time) {
  835. if (!this.isLock) {
  836. return;
  837. }
  838. if (this.docDetail.lockname != this.usrInfo.username) {
  839. return;
  840. }
  841. this.__continueLock = $A.randomString(6);
  842. let tempString = this.__continueLock;
  843. setTimeout(() => {
  844. if (tempString != this.__continueLock) {
  845. return;
  846. }
  847. if (!this.isLock) {
  848. return;
  849. }
  850. if (this.docDetail.lockname != this.usrInfo.username) {
  851. return;
  852. }
  853. this.handleClick('lock');
  854. }, time);
  855. },
  856. exportMenu(act) {
  857. switch (this.docDetail.type) {
  858. case 'mind':
  859. this.$refs.myMind.exportHandle(act == 'pdf' ? 1 : 0, this.docDetail.title);
  860. break;
  861. case 'flow':
  862. this.$refs.myFlow[act == 'pdf' ? 'exportPDF' : 'exportPNG'](this.docDetail.title, 3);
  863. break;
  864. case 'sheet':
  865. this.$refs.mySheet.exportExcel(this.docDetail.title, act);
  866. break;
  867. }
  868. }
  869. },
  870. }
  871. </script>