edit.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  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%"></TEditor>
  73. </template>
  74. <minder v-else-if="docDetail.type=='mind'" ref="myMind" class="body-mind" v-model="docContent"></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"></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. userInfo: {},
  346. routeName: '',
  347. synergyNum: 0,
  348. synchUsers: [],
  349. timeValue: Math.round(new Date().getTime() / 1000),
  350. }
  351. },
  352. created() {
  353. this.historyColumns = [{
  354. "title": this.$L("存档日期"),
  355. "minWidth": 160,
  356. "maxWidth": 200,
  357. render: (h, params) => {
  358. return h('span', $A.formatDate("Y-m-d H:i:s", params.row.indate));
  359. }
  360. }, {
  361. "title": this.$L("操作员"),
  362. "key": 'username',
  363. "minWidth": 80,
  364. "maxWidth": 130,
  365. render: (h, params) => {
  366. return h('UserView', {
  367. props: {
  368. username: params.row.username
  369. }
  370. });
  371. }
  372. }, {
  373. "title": " ",
  374. "key": 'action',
  375. "width": 80,
  376. "align": 'center',
  377. render: (h, params) => {
  378. if (this.hid == params.row.id || (this.hid == 0 && params.index == 0)) {
  379. return h('Icon', {
  380. props: { type: 'md-checkmark' },
  381. style: { marginRight: '6px', fontSize: '16px', color: '#FF5722' },
  382. });
  383. }
  384. return h('Button', {
  385. props: {
  386. type: 'text',
  387. size: 'small'
  388. },
  389. style: {
  390. fontSize: '12px'
  391. },
  392. on: {
  393. click: () => {
  394. let data = {sid: this.getSid() + "-" + params.row.id, other: this.$route.params.other}
  395. if (params.index == 0) {
  396. data.sid = this.getSid();
  397. }
  398. this.handleSection('openBefore', data);
  399. }
  400. }
  401. }, this.$L('还原'));
  402. }
  403. }];
  404. },
  405. mounted() {
  406. this.routeName = this.$route.name;
  407. this.userInfo = $A.getUserInfo((res, isLogin) => {
  408. this.userInfo = res;
  409. }, false);
  410. //
  411. setInterval(() => {
  412. if (this.routeName === this.$route.name) {
  413. this.timeValue = Math.round(new Date().getTime() / 1000);
  414. }
  415. });
  416. //
  417. $(window).bind('beforeunload', () => {
  418. if (!this.equalContent && this.routeName === this.$route.name) {
  419. return '是否放弃修改的内容返回?';
  420. }
  421. });
  422. //
  423. $A.WSOB.setOnMsgListener("chat/index", ['docs'], (msgDetail) => {
  424. if (this.routeName !== this.$route.name) {
  425. return;
  426. }
  427. let body = msgDetail.body;
  428. if (body.sid != this.sid) {
  429. return;
  430. }
  431. switch (body.type) {
  432. case 'users':
  433. this.synchUsers = body.lists;
  434. this.synchUsers.splice(this.synchUsers.length);
  435. break;
  436. case 'update':
  437. this.$Modal.confirm({
  438. title: this.$L("更新提示"),
  439. content: this.$L('团队成员(%)更新了内容,<br/>更新时间:%。<br/><br/>点击【确定】加载最新内容。', body.nickname, $A.formatDate("Y-m-d H:i:s", body.time)),
  440. onOk: () => {
  441. this.refreshDetail();
  442. }
  443. });
  444. break;
  445. case 'lock':
  446. case 'unlock':
  447. if (this.docDetail.lockname == body.lockname) {
  448. return;
  449. }
  450. this.$set(this.docDetail, 'lockname', body.lockname);
  451. this.$set(this.docDetail, 'lockdate', body.lockdate);
  452. this.$Notice.close('docs-lock')
  453. this.$Notice[body.type=='lock'?'warning':'info']({
  454. name: 'docs-lock',
  455. duration: 0,
  456. render: h => {
  457. return h('div', {
  458. style: {
  459. lineHeight: '18px'
  460. }
  461. }, [
  462. h('span', {
  463. style: {
  464. fontWeight: 500
  465. }
  466. }, body.nickname + ':'),
  467. h('span', {
  468. style: {
  469. paddingLeft: '6px'
  470. }
  471. }, this.$L(body.type == 'lock' ? '锁定文档' : '解锁文档'))
  472. ])
  473. }
  474. });
  475. break;
  476. }
  477. });
  478. },
  479. activated() {
  480. this.docDrawerTab = '';
  481. this.sectionNoDataText = '';
  482. this.historyNoDataText = '';
  483. //
  484. this.refreshSid();
  485. this.synergy(true);
  486. },
  487. deactivated() {
  488. if (this.isLock && this.docDetail.lockname == this.userInfo.username) {
  489. this.docDetail.lockname = '';
  490. this.handleClick('unlock');
  491. }
  492. this.$Notice.close('docs-lock');
  493. //
  494. if (!this.equalContent) {
  495. this.handleClick('save');
  496. }
  497. //
  498. this.synergy(false);
  499. this.docDrawerShow = false;
  500. if ($A.getToken() === false) {
  501. this.sid = 0;
  502. }
  503. },
  504. watch: {
  505. sid(val) {
  506. if (!val) {
  507. this.goBackDirect();
  508. return;
  509. }
  510. this.hid = $A.runNum($A.strExists(val, '-') ? $A.getMiddle(val, "-", null) : 0);
  511. this.refreshDetail();
  512. },
  513. '$route' (To) {
  514. if (To.name == 'docs-edit') {
  515. this.sid = To.params.sid;
  516. }
  517. },
  518. docDrawerTab(act) {
  519. switch (act) {
  520. case "menu":
  521. if (!this.sectionNoDataText) {
  522. this.sectionNoDataText = this.$L("数据加载中.....");
  523. let bookid = this.docDetail.bookid;
  524. $A.apiAjax({
  525. url: 'docs/section/lists',
  526. data: {
  527. act: 'edit',
  528. bookid: bookid
  529. },
  530. error: () => {
  531. if (bookid != this.docDetail.bookid) {
  532. return;
  533. }
  534. this.sectionNoDataText = this.$L("数据加载失败!");
  535. },
  536. success: (res) => {
  537. if (bookid != this.docDetail.bookid) {
  538. return;
  539. }
  540. if (res.ret === 1) {
  541. this.sectionLists = res.data.tree;
  542. this.sectionNoDataText = this.$L("没有相关的数据");
  543. }else{
  544. this.sectionLists = [];
  545. this.sectionNoDataText = res.msg;
  546. }
  547. }
  548. });
  549. }
  550. break;
  551. case "history":
  552. if (!this.historyNoDataText) {
  553. this.historyNoDataText = this.$L("数据加载中.....");
  554. let sid = this.getSid();
  555. $A.apiAjax({
  556. url: 'docs/section/history',
  557. data: {
  558. id: sid,
  559. pagesize: 50
  560. },
  561. error: () => {
  562. if (sid != this.getSid()) {
  563. return;
  564. }
  565. this.historyNoDataText = this.$L("数据加载失败!");
  566. },
  567. success: (res) => {
  568. if (sid != this.getSid()) {
  569. return;
  570. }
  571. if (res.ret === 1) {
  572. this.historyLists = res.data;
  573. this.historyNoDataText = this.$L("没有相关的数据");
  574. }else{
  575. this.historyLists = [];
  576. this.historyNoDataText = res.msg;
  577. }
  578. }
  579. });
  580. }
  581. break;
  582. }
  583. }
  584. },
  585. computed: {
  586. equalContent() {
  587. return this.bakContent == $A.jsonStringify(this.docContent);
  588. },
  589. synchUsersS() {
  590. return this.synchUsers.filter(item => {
  591. return item.indate + 20 > this.timeValue;
  592. });
  593. },
  594. isLock() {
  595. return !!(this.docDetail.lockname && this.docDetail.lockdate > this.timeValue - 60);
  596. }
  597. },
  598. methods: {
  599. goBackDirect() {
  600. this.bakContent = $A.jsonStringify(this.docContent);
  601. this.goBack({name:'docs'});
  602. },
  603. synergy(enter) {
  604. if (enter === false) {
  605. $A.WSOB.sendTo('docs', {
  606. type: 'quit',
  607. sid: this.sid,
  608. username: this.userInfo.username,
  609. });
  610. } else {
  611. if (this.routeName !== this.$route.name) {
  612. let tmpNum = this.synergyNum;
  613. setTimeout(() => {
  614. if (tmpNum === this.synergyNum) {
  615. this.synergyNum++;
  616. this.synergy();
  617. }
  618. }, 10000);
  619. } else {
  620. $A.WSOB.sendTo('docs', null, {
  621. type: enter === true ? 'enter' : 'refresh',
  622. sid: this.sid,
  623. nickname: this.userInfo.nickname,
  624. username: this.userInfo.username,
  625. userimg: this.userInfo.userimg,
  626. indate: Math.round(new Date().getTime() / 1000),
  627. }, (res) => {
  628. this.synchUsers = res.status === 1 ? res.message : [];
  629. let tmpNum = this.synergyNum;
  630. setTimeout(() => {
  631. if (tmpNum === this.synergyNum) {
  632. this.synergyNum++;
  633. this.synergy();
  634. }
  635. }, 10000);
  636. });
  637. }
  638. }
  639. },
  640. refreshSid() {
  641. this.sid = this.$route.params.sid;
  642. if (typeof this.$route.params.other === "object") {
  643. this.$set(this.docDetail, 'title', $A.getObject(this.$route.params.other, 'title'))
  644. }
  645. },
  646. getSid() {
  647. return $A.runNum($A.getMiddle(this.sid, null, '-'));
  648. },
  649. refreshDetail() {
  650. this.docDetail = { };
  651. this.docContent = { };
  652. this.bakContent = null;
  653. this.getDetail();
  654. },
  655. getDetail() {
  656. this.loadIng++;
  657. $A.apiAjax({
  658. url: 'docs/section/content',
  659. data: {
  660. act: 'edit',
  661. id: this.sid,
  662. },
  663. complete: () => {
  664. this.loadIng--;
  665. },
  666. error: () => {
  667. this.goBackDirect();
  668. alert(this.$L('网络繁忙,请稍后再试!'));
  669. },
  670. success: (res) => {
  671. if (res.ret === 1) {
  672. this.docDetail = res.data;
  673. this.docContent = $A.jsonParse(res.data.content);
  674. this.bakContent = this.hid == 0 ? $A.jsonStringify(this.docContent) : '';
  675. this.continueLock(1000);
  676. } else {
  677. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  678. }
  679. }
  680. });
  681. },
  682. handleSection(act, detail) {
  683. switch (act) {
  684. case 'open':
  685. this.handleSection('openBefore', {sid: detail.id, other: detail || {}})
  686. break;
  687. case 'openBefore':
  688. if (!this.equalContent) {
  689. this.$Modal.confirm({
  690. title: this.$L('温馨提示'),
  691. content: this.$L('是否放弃保存修改的内容?'),
  692. cancelText: this.$L('取消'),
  693. okText: this.$L('放弃保存'),
  694. onOk: () => {
  695. this.handleSection('openConfirm', detail)
  696. }
  697. });
  698. } else {
  699. this.handleSection('openConfirm', detail)
  700. }
  701. break;
  702. case 'openConfirm':
  703. this.goForward({name: 'docs-edit', params: detail}, true);
  704. this.refreshSid();
  705. this.docDrawerShow = false;
  706. break;
  707. }
  708. },
  709. handleSynch(username) {
  710. if (username == this.userInfo.username) {
  711. return;
  712. }
  713. if (typeof window.onChatOpenUserName === "function") {
  714. window.onChatOpenUserName(username);
  715. }
  716. },
  717. handleClick(act) {
  718. switch (act) {
  719. case "back":
  720. if (this.equalContent) {
  721. this.goBackDirect();
  722. return;
  723. }
  724. this.$Modal.confirm({
  725. title: this.$L('温馨提示'),
  726. content: this.$L('是否放弃修改的内容返回?'),
  727. cancelText: this.$L('放弃保存'),
  728. onCancel: () => {
  729. this.goBackDirect();
  730. },
  731. okText: this.$L('保存并返回'),
  732. onOk: () => {
  733. this.handleClick('save');
  734. this.goBackDirect();
  735. }
  736. });
  737. break;
  738. case "save":
  739. this.bakContent = $A.jsonStringify(this.docContent);
  740. $A.apiAjax({
  741. url: 'docs/section/save',
  742. method: 'post',
  743. data: Object.assign(this.docDetail, {
  744. id: this.getSid(),
  745. content: this.bakContent
  746. }),
  747. error: () => {
  748. this.bakContent = '';
  749. alert(this.$L('网络繁忙,保存失败!'));
  750. },
  751. success: (res) => {
  752. if (res.ret === 1) {
  753. this.$Message.success(res.msg);
  754. this.historyNoDataText = '';
  755. if (this.hid != 0) {
  756. this.hid = 0;
  757. this.goForward({name: 'docs-edit', params: {sid: this.getSid()}}, true);
  758. }
  759. } else {
  760. this.bakContent = '';
  761. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  762. }
  763. }
  764. });
  765. break;
  766. case "menu":
  767. case "history":
  768. this.docDrawerTab = act;
  769. this.docDrawerShow = true
  770. break;
  771. case "share":
  772. this.$Modal.confirm({
  773. render: (h) => {
  774. return h('div', [
  775. h('div', {
  776. style: {
  777. fontSize: '16px',
  778. fontWeight: '500',
  779. marginBottom: '20px',
  780. }
  781. }, this.$L('文档链接')),
  782. h('Input', {
  783. props: {
  784. value: this.handleClick('view'),
  785. readonly: true,
  786. },
  787. })
  788. ])
  789. },
  790. });
  791. break;
  792. case "lock":
  793. case "unlock":
  794. $A.apiAjax({
  795. url: 'docs/section/lock?id=' + this.getSid(),
  796. data: {
  797. act: act,
  798. },
  799. error: () => {
  800. alert(this.$L('网络繁忙,请稍后再试!'));
  801. },
  802. success: (res) => {
  803. if (res.ret === 1) {
  804. if (this.docDetail.lockname != res.data.lockname) {
  805. this.$Message.success(res.msg);
  806. }
  807. this.$set(this.docDetail, 'lockname', res.data.lockname);
  808. this.$set(this.docDetail, 'lockdate', res.data.lockdate);
  809. this.continueLock(20000);
  810. } else {
  811. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  812. }
  813. }
  814. });
  815. break;
  816. case "view":
  817. return $A.webUrl('docs/view/' + this.docDetail.id);
  818. }
  819. },
  820. continueLock(time) {
  821. if (!this.isLock) {
  822. return;
  823. }
  824. if (this.docDetail.lockname != this.userInfo.username) {
  825. return;
  826. }
  827. this.__continueLock = $A.randomString(6);
  828. let tempString = this.__continueLock;
  829. setTimeout(() => {
  830. if (tempString != this.__continueLock) {
  831. return;
  832. }
  833. if (!this.isLock) {
  834. return;
  835. }
  836. if (this.docDetail.lockname != this.userInfo.username) {
  837. return;
  838. }
  839. this.handleClick('lock');
  840. }, time);
  841. },
  842. exportMenu(act) {
  843. switch (this.docDetail.type) {
  844. case 'mind':
  845. this.$refs.myMind.exportHandle(act == 'pdf' ? 1 : 0, this.docDetail.title);
  846. break;
  847. case 'flow':
  848. this.$refs.myFlow[act == 'pdf' ? 'exportPDF' : 'exportPNG'](this.docDetail.title, 1);
  849. break;
  850. case 'sheet':
  851. this.$refs.mySheet.exportExcel(this.docDetail.title, act);
  852. break;
  853. }
  854. }
  855. },
  856. }
  857. </script>