edit.vue 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  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. 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. document.addEventListener("keydown", this.keySave);
  487. },
  488. deactivated() {
  489. if (this.isLock && this.docDetail.lockname == this.userInfo.username) {
  490. this.docDetail.lockname = '';
  491. this.handleClick('unlock');
  492. }
  493. this.$Notice.close('docs-lock');
  494. //
  495. if (!this.equalContent) {
  496. this.handleClick('save');
  497. }
  498. //
  499. this.synergy(false);
  500. document.removeEventListener("keydown", this.keySave);
  501. this.docDrawerShow = false;
  502. if ($A.getToken() === false) {
  503. this.sid = 0;
  504. }
  505. },
  506. watch: {
  507. sid(val) {
  508. if (!val) {
  509. this.goBackDirect();
  510. return;
  511. }
  512. this.hid = $A.runNum($A.strExists(val, '-') ? $A.getMiddle(val, "-", null) : 0);
  513. this.refreshDetail();
  514. },
  515. '$route' (To) {
  516. if (To.name == 'docs-edit') {
  517. this.sid = To.params.sid;
  518. }
  519. },
  520. docDrawerTab(act) {
  521. switch (act) {
  522. case "menu":
  523. if (!this.sectionNoDataText) {
  524. this.sectionNoDataText = this.$L("数据加载中.....");
  525. let bookid = this.docDetail.bookid;
  526. $A.apiAjax({
  527. url: 'docs/section/lists',
  528. data: {
  529. act: 'edit',
  530. bookid: bookid
  531. },
  532. error: () => {
  533. if (bookid != this.docDetail.bookid) {
  534. return;
  535. }
  536. this.sectionNoDataText = this.$L("数据加载失败!");
  537. },
  538. success: (res) => {
  539. if (bookid != this.docDetail.bookid) {
  540. return;
  541. }
  542. if (res.ret === 1) {
  543. this.sectionLists = res.data.tree;
  544. this.sectionNoDataText = this.$L("没有相关的数据");
  545. }else{
  546. this.sectionLists = [];
  547. this.sectionNoDataText = res.msg;
  548. }
  549. }
  550. });
  551. }
  552. break;
  553. case "history":
  554. if (!this.historyNoDataText) {
  555. this.historyNoDataText = this.$L("数据加载中.....");
  556. let sid = this.getSid();
  557. $A.apiAjax({
  558. url: 'docs/section/history',
  559. data: {
  560. id: sid,
  561. pagesize: 50
  562. },
  563. error: () => {
  564. if (sid != this.getSid()) {
  565. return;
  566. }
  567. this.historyNoDataText = this.$L("数据加载失败!");
  568. },
  569. success: (res) => {
  570. if (sid != this.getSid()) {
  571. return;
  572. }
  573. if (res.ret === 1) {
  574. this.historyLists = res.data;
  575. this.historyNoDataText = this.$L("没有相关的数据");
  576. }else{
  577. this.historyLists = [];
  578. this.historyNoDataText = res.msg;
  579. }
  580. }
  581. });
  582. }
  583. break;
  584. }
  585. }
  586. },
  587. computed: {
  588. equalContent() {
  589. return this.bakContent == $A.jsonStringify(this.docContent);
  590. },
  591. synchUsersS() {
  592. return this.synchUsers.filter(item => {
  593. return item.indate + 20 > this.timeValue;
  594. });
  595. },
  596. isLock() {
  597. return !!(this.docDetail.lockname && this.docDetail.lockdate > this.timeValue - 60);
  598. }
  599. },
  600. methods: {
  601. keySave(e) {
  602. if ((e.ctrlKey || e.metaKey) && e.keyCode === 83) {
  603. this.handleClick('saveBefore');
  604. e.preventDefault();
  605. }
  606. },
  607. goBackDirect() {
  608. this.bakContent = $A.jsonStringify(this.docContent);
  609. this.goBack({name:'docs'});
  610. },
  611. synergy(enter) {
  612. if (enter === false) {
  613. $A.WSOB.sendTo('docs', {
  614. type: 'quit',
  615. sid: this.sid,
  616. username: this.userInfo.username,
  617. });
  618. } else {
  619. if (this.routeName !== this.$route.name) {
  620. let tmpNum = this.synergyNum;
  621. setTimeout(() => {
  622. if (tmpNum === this.synergyNum) {
  623. this.synergyNum++;
  624. this.synergy();
  625. }
  626. }, 10000);
  627. } else {
  628. $A.WSOB.sendTo('docs', null, {
  629. type: enter === true ? 'enter' : 'refresh',
  630. sid: this.sid,
  631. nickname: this.userInfo.nickname,
  632. username: this.userInfo.username,
  633. userimg: this.userInfo.userimg,
  634. indate: Math.round(new Date().getTime() / 1000),
  635. }, (res) => {
  636. this.synchUsers = res.status === 1 ? res.message : [];
  637. let tmpNum = this.synergyNum;
  638. setTimeout(() => {
  639. if (tmpNum === this.synergyNum) {
  640. this.synergyNum++;
  641. this.synergy();
  642. }
  643. }, 10000);
  644. });
  645. }
  646. }
  647. },
  648. refreshSid() {
  649. this.sid = this.$route.params.sid;
  650. if (typeof this.$route.params.other === "object") {
  651. this.$set(this.docDetail, 'title', $A.getObject(this.$route.params.other, 'title'))
  652. }
  653. },
  654. getSid() {
  655. return $A.runNum($A.getMiddle(this.sid, null, '-'));
  656. },
  657. refreshDetail() {
  658. this.docDetail = { };
  659. this.docContent = { };
  660. this.bakContent = null;
  661. this.getDetail();
  662. },
  663. getDetail() {
  664. this.loadIng++;
  665. $A.apiAjax({
  666. url: 'docs/section/content',
  667. data: {
  668. act: 'edit',
  669. id: this.sid,
  670. },
  671. complete: () => {
  672. this.loadIng--;
  673. },
  674. error: () => {
  675. this.goBackDirect();
  676. alert(this.$L('网络繁忙,请稍后再试!'));
  677. },
  678. success: (res) => {
  679. if (res.ret === 1) {
  680. this.docDetail = res.data;
  681. this.docContent = $A.jsonParse(res.data.content);
  682. this.bakContent = this.hid == 0 ? $A.jsonStringify(this.docContent) : '';
  683. this.continueLock(1000);
  684. } else {
  685. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  686. }
  687. }
  688. });
  689. },
  690. handleSection(act, detail) {
  691. switch (act) {
  692. case 'open':
  693. this.handleSection('openBefore', {sid: detail.id, other: detail || {}})
  694. break;
  695. case 'openBefore':
  696. if (!this.equalContent) {
  697. this.$Modal.confirm({
  698. title: this.$L('温馨提示'),
  699. content: this.$L('是否放弃保存修改的内容?'),
  700. cancelText: this.$L('取消'),
  701. okText: this.$L('放弃保存'),
  702. onOk: () => {
  703. this.handleSection('openConfirm', detail)
  704. }
  705. });
  706. } else {
  707. this.handleSection('openConfirm', detail)
  708. }
  709. break;
  710. case 'openConfirm':
  711. this.goForward({name: 'docs-edit', params: detail}, true);
  712. this.refreshSid();
  713. this.docDrawerShow = false;
  714. break;
  715. }
  716. },
  717. handleSynch(username) {
  718. if (username == this.userInfo.username) {
  719. return;
  720. }
  721. if (typeof window.onChatOpenUserName === "function") {
  722. window.onChatOpenUserName(username);
  723. }
  724. },
  725. handleClick(act) {
  726. switch (act) {
  727. case "back":
  728. if (this.equalContent) {
  729. this.goBackDirect();
  730. return;
  731. }
  732. this.$Modal.confirm({
  733. title: this.$L('温馨提示'),
  734. content: this.$L('是否放弃修改的内容返回?'),
  735. cancelText: this.$L('放弃保存'),
  736. onCancel: () => {
  737. this.goBackDirect();
  738. },
  739. okText: this.$L('保存并返回'),
  740. onOk: () => {
  741. this.handleClick('save');
  742. this.goBackDirect();
  743. }
  744. });
  745. break;
  746. case "saveBefore":
  747. if (!this.equalContent && this.loadIng == 0) {
  748. this.handleClick('save');
  749. } else {
  750. this.$Message.warning(this.$L('没有任何修改!'));
  751. }
  752. return;
  753. case "save":
  754. this.bakContent = $A.jsonStringify(this.docContent);
  755. $A.apiAjax({
  756. url: 'docs/section/save',
  757. method: 'post',
  758. data: Object.assign(this.docDetail, {
  759. id: this.getSid(),
  760. content: this.bakContent
  761. }),
  762. error: () => {
  763. this.bakContent = '';
  764. alert(this.$L('网络繁忙,保存失败!'));
  765. },
  766. success: (res) => {
  767. if (res.ret === 1) {
  768. this.$Message.success(res.msg);
  769. this.historyNoDataText = '';
  770. if (this.hid != 0) {
  771. this.hid = 0;
  772. this.goForward({name: 'docs-edit', params: {sid: this.getSid()}}, true);
  773. }
  774. } else {
  775. this.bakContent = '';
  776. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  777. }
  778. }
  779. });
  780. break;
  781. case "menu":
  782. case "history":
  783. this.docDrawerTab = act;
  784. this.docDrawerShow = true
  785. break;
  786. case "share":
  787. this.$Modal.confirm({
  788. render: (h) => {
  789. return h('div', [
  790. h('div', {
  791. style: {
  792. fontSize: '16px',
  793. fontWeight: '500',
  794. marginBottom: '20px',
  795. }
  796. }, this.$L('文档链接')),
  797. h('Input', {
  798. props: {
  799. value: this.handleClick('view'),
  800. readonly: true,
  801. },
  802. })
  803. ])
  804. },
  805. });
  806. break;
  807. case "lock":
  808. case "unlock":
  809. $A.apiAjax({
  810. url: 'docs/section/lock?id=' + this.getSid(),
  811. data: {
  812. act: act,
  813. },
  814. error: () => {
  815. alert(this.$L('网络繁忙,请稍后再试!'));
  816. },
  817. success: (res) => {
  818. if (res.ret === 1) {
  819. if (this.docDetail.lockname != res.data.lockname) {
  820. this.$Message.success(res.msg);
  821. }
  822. this.$set(this.docDetail, 'lockname', res.data.lockname);
  823. this.$set(this.docDetail, 'lockdate', res.data.lockdate);
  824. this.continueLock(20000);
  825. } else {
  826. this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
  827. }
  828. }
  829. });
  830. break;
  831. case "view":
  832. return $A.webUrl('docs/view/' + this.docDetail.id);
  833. }
  834. },
  835. continueLock(time) {
  836. if (!this.isLock) {
  837. return;
  838. }
  839. if (this.docDetail.lockname != this.userInfo.username) {
  840. return;
  841. }
  842. this.__continueLock = $A.randomString(6);
  843. let tempString = this.__continueLock;
  844. setTimeout(() => {
  845. if (tempString != this.__continueLock) {
  846. return;
  847. }
  848. if (!this.isLock) {
  849. return;
  850. }
  851. if (this.docDetail.lockname != this.userInfo.username) {
  852. return;
  853. }
  854. this.handleClick('lock');
  855. }, time);
  856. },
  857. exportMenu(act) {
  858. switch (this.docDetail.type) {
  859. case 'mind':
  860. this.$refs.myMind.exportHandle(act == 'pdf' ? 1 : 0, this.docDetail.title);
  861. break;
  862. case 'flow':
  863. this.$refs.myFlow[act == 'pdf' ? 'exportPDF' : 'exportPNG'](this.docDetail.title, 1);
  864. break;
  865. case 'sheet':
  866. this.$refs.mySheet.exportExcel(this.docDetail.title, act);
  867. break;
  868. }
  869. }
  870. },
  871. }
  872. </script>