edit.vue 36 KB

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