viewer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. import { defineStore } from 'pinia'
  2. import core from '@/core'
  3. export const useViewerStore = defineStore({
  4. id: 'viewer',
  5. state: () => ({
  6. fullMode: false,
  7. currentPage: 0,
  8. searchStatus: false,
  9. scale: '',
  10. oldScale: '',
  11. newScale: '',
  12. themeMode: 'Light',
  13. pageMode: 0,
  14. webviewerMode: 'Standalone',
  15. scrollMode: 'Vertical',
  16. pageLabels: [],
  17. zoomLevel: ['auto', 'page-fit', 0.5, 1, 1.25, 1.5, 2, 2.5],
  18. activeTab: 0,
  19. activeStickNote: false,
  20. activeActiveMeasure: false,
  21. activeHand: false,
  22. verified: false,
  23. activeElements: {
  24. leftPanel: false,
  25. rightPanel: false,
  26. pageModePanel: false,
  27. stampPanel: false,
  28. linkPanel: false,
  29. compareSettingDialog: false,
  30. languageDialog: false,
  31. setPasswordModal: false,
  32. signCreatePanel: false,
  33. downloadSettingDialog: false,
  34. printSettingDialog: false,
  35. editTextPanel: false,
  36. preventDialog: false,
  37. insertPageSettingDialog: false,
  38. deletePageDialog: false
  39. },
  40. activeElementsTab: {
  41. leftPanelTab: 'THUMBS',
  42. rightPanelTab: 'GENERAL',
  43. stampPanelTab: 'STANDARD',
  44. signPanelTab: 'trackpad'
  45. },
  46. headers: [
  47. {
  48. type: 'toggleElementButton',
  49. img: 'icon-header-sidebar-line',
  50. element: 'leftPanel',
  51. dataElement: 'leftPanelButton',
  52. title: 'Left Panel',
  53. class: 'toggle-button'
  54. },
  55. {
  56. type: 'divider',
  57. hidden: [
  58. 'small-mobile'
  59. ]
  60. },
  61. {
  62. type: 'pageDisplayButton',
  63. dataElement: 'pageDisplayButton',
  64. element: 'pageDisplayButton',
  65. title: 'Page Display'
  66. },
  67. {
  68. type: 'fullScreenButton',
  69. dataElement: 'fullScreenButton',
  70. element: 'fullScreenButton',
  71. title: 'Full Screen'
  72. },
  73. {
  74. type: 'handToolButton',
  75. dataElement: 'handToolButton',
  76. element: 'handToolButton',
  77. title: 'Pan Tool'
  78. },
  79. {
  80. type: 'divider',
  81. hidden: [
  82. 'small-mobile'
  83. ]
  84. },
  85. {
  86. type: 'zoomOverlay',
  87. dataElement: 'zoomOverlayButton',
  88. element: 'zoomOverlay',
  89. hiddenOnMobileDevice: true
  90. },
  91. {
  92. type: 'divider',
  93. hidden: [
  94. 'small-mobile'
  95. ]
  96. },
  97. {
  98. type: 'themeMode',
  99. dataElement: 'themeMode',
  100. element: 'themeMode'
  101. },
  102. {
  103. type: 'stickyNoteButton',
  104. dataElement: 'stickyNoteButton',
  105. element: 'stickyNoteButton',
  106. hidden: false,
  107. },
  108. {
  109. type: 'measureButton',
  110. dataElement: 'measureButton',
  111. element: 'measureButton',
  112. hidden: true,
  113. },
  114. {
  115. type: 'compareButton',
  116. dataElement: 'compareButton',
  117. element: 'compareButton',
  118. hidden: true,
  119. },
  120. {
  121. type: 'saveButton',
  122. dataElement: 'saveButton',
  123. element: 'saveButton',
  124. hidden: true,
  125. }
  126. ],
  127. rightHeaders: [
  128. {
  129. type: 'openFileButton',
  130. dataElement: 'openFileButton',
  131. element: 'openFileButton',
  132. title: 'Open File'
  133. },
  134. {
  135. type: 'searchButton',
  136. dataElement: 'searchButton',
  137. element: 'searchButton',
  138. title: 'Search'
  139. },
  140. {
  141. type: 'toggleRightPanelButton',
  142. img: 'icon-header-sidebar-line',
  143. element: 'rightPanel',
  144. dataElement: 'rightPanelButton',
  145. title: 'Right Panel',
  146. id: 'propertyPanelButton'
  147. },
  148. {
  149. type: 'downloadButton',
  150. dataElement: 'downloadButton',
  151. element: 'downloadButton',
  152. title: 'Download'
  153. },
  154. {
  155. type: 'flattenButton',
  156. dataElement: 'flattenButton',
  157. element: 'flattenButton',
  158. title: 'Save as Flattened PDF'
  159. },
  160. {
  161. type: 'printButton',
  162. dataElement: 'printButton',
  163. element: 'printButton',
  164. title: 'Print'
  165. }
  166. ],
  167. toolMode: 'view',
  168. tools: {
  169. annotation: [
  170. {
  171. type: 'markup',
  172. dataElement: 'markup',
  173. element: 'markup',
  174. hidden: false,
  175. }
  176. ],
  177. form: [
  178. {
  179. type: 'textFieldButton',
  180. dataElement: 'textFieldButton',
  181. element: 'textFieldButton',
  182. title: 'Form Field'
  183. },
  184. {
  185. type: 'checkBoxButton',
  186. dataElement: 'checkBoxButton',
  187. element: 'checkBoxButton',
  188. title: 'Check Box'
  189. },
  190. {
  191. type: 'radioButton',
  192. dataElement: 'radioButton',
  193. element: 'radioButton',
  194. title: 'Radio Button'
  195. },
  196. {
  197. type: 'listBox',
  198. dataElement: 'listBox',
  199. element: 'listBox',
  200. title: 'List Box'
  201. },
  202. {
  203. type: 'comboBox',
  204. dataElement: 'comboBox',
  205. element: 'comboBox',
  206. title: 'Combo Box'
  207. },
  208. {
  209. type: 'pushButton',
  210. dataElement: 'pushButton',
  211. element: 'pushButton',
  212. title: 'Push Button'
  213. }
  214. ],
  215. security: [
  216. {
  217. type: 'securitySelect',
  218. dataElement: 'securitySelect',
  219. element: 'securitySelect',
  220. title: 'Security'
  221. },
  222. {
  223. type: 'watermarkSelect',
  224. dataElement: 'watermarkSelect',
  225. element: 'watermarkSelect',
  226. title: 'Watermark'
  227. }
  228. ],
  229. compare: [
  230. {
  231. type: 'comparedToolbar'
  232. }
  233. ],
  234. editor: [
  235. {
  236. type: 'editTextToolbar'
  237. }
  238. ]
  239. },
  240. downloading: false,
  241. downloadError: '',
  242. popoverChanged: false,
  243. /* '': 不在compare模式下
  244. 'finished': 覆盖对比完成
  245. 'end': 覆盖对比完成,关闭对比结果,回到初始对比页面
  246. 'next': 内容对比完成 */
  247. compareStatus: '',
  248. upload: true, // 未上传文件的upload按钮
  249. uploadLoading: false, // 上传中的loading效果
  250. compareMode: 'content'
  251. }),
  252. getters: {
  253. getFullMode () {
  254. return this.fullMode
  255. },
  256. getCurrentPage () {
  257. return this.currentPage
  258. },
  259. getThemeMode () {
  260. return this.themeMode
  261. },
  262. getPageMode () {
  263. return this.pageMode
  264. },
  265. getScrollMode () {
  266. return this.scrollMode
  267. },
  268. getWebviewerMode () {
  269. return this.webviewerMode
  270. },
  271. getActiveHeaderItems () {
  272. return this.headers
  273. },
  274. getActiveRightHeaderItems () {
  275. return this.rightHeaders
  276. },
  277. isElementOpen: (state) => {
  278. return (dataElement) => state.activeElements[dataElement]
  279. },
  280. getActiveElementTab: (state) => {
  281. return (dataElement) => state.activeElementsTab[dataElement]
  282. },
  283. getScale () {
  284. return Math.round(this.scale * 100)
  285. },
  286. getOldScale () {
  287. return Math.round(this.oldScale * 100)
  288. },
  289. getNewScale () {
  290. return Math.round(this.newScale * 100)
  291. },
  292. getActiveStickNote () {
  293. return this.activeStickNote
  294. },
  295. getActiveMeasure () {
  296. return this.activeActiveMeasure
  297. },
  298. getActiveHand () {
  299. return this.activeHand
  300. },
  301. getSearchStatus () {
  302. return this.searchStatus
  303. },
  304. getToolMode () {
  305. return this.toolMode
  306. },
  307. getToolItems () {
  308. return this.tools
  309. },
  310. getDownloading () {
  311. return this.downloading
  312. },
  313. getDownloadError () {
  314. return this.downloadError
  315. },
  316. getPopoverChanged () {
  317. return this.popoverChanged
  318. },
  319. getCompareStatus () {
  320. return this.compareStatus
  321. },
  322. getUpload () {
  323. return this.upload
  324. },
  325. getUploadLoading () {
  326. return this.uploadLoading
  327. },
  328. getCompareMode () {
  329. return this.compareMode
  330. },
  331. getVerified () {
  332. return this.verified
  333. }
  334. },
  335. actions: {
  336. resetSetting () {
  337. this.fullMode = false
  338. this.currentPage = 0
  339. this.scale = '',
  340. this.themeMode = 'Light'
  341. this.pageMode = 0
  342. this.scrollMode = 'Vertical'
  343. this.activeTab = 0
  344. this.searchStatus = false
  345. this.activeElements = {
  346. leftPanel: false,
  347. rightPanel: false,
  348. pageModePanel: false,
  349. stampPanel: false,
  350. linkPanel: false,
  351. compareSettingDialog: false,
  352. languageDialog: false,
  353. preventDialog: false,
  354. setPasswordModal: false,
  355. signCreatePanel: false,
  356. downloadSettingDialog: false,
  357. printSettingDialog: false,
  358. editTextPanel: false,
  359. insertPageSettingDialog: false,
  360. deletePageDialog: false
  361. },
  362. this.activeElementsTab = {
  363. leftPanelTab: 'THUMBS',
  364. rightPanelTab: 'GENERAL',
  365. stampPanelTab: 'STANDARD',
  366. signPanelTab: 'trackpad'
  367. }
  368. },
  369. resetPanels () {
  370. this.searchStatus = false
  371. this.activeElements = {
  372. leftPanel: false,
  373. rightPanel: false,
  374. pageModePanel: false,
  375. stampPanel: false
  376. }
  377. },
  378. setVierified (verified) {
  379. this.verified = verified
  380. },
  381. setFullMode (fullMode) {
  382. return this.fullMode = fullMode
  383. },
  384. setCurrentPage (currentPage) {
  385. this.currentPage = currentPage
  386. },
  387. setThemeMode (themeMode) {
  388. this.themeMode = themeMode
  389. },
  390. setPageMode (mode) {
  391. this.pageMode = mode
  392. },
  393. setScrollMode (mode) {
  394. this.scrollMode = mode
  395. },
  396. setWebviewerMode (mode) {
  397. this.webviewerMode = mode
  398. },
  399. setCurrentScale (scale) {
  400. this.scale = scale
  401. },
  402. setOldCurrentScale (scale) {
  403. this.oldScale = scale
  404. },
  405. setNewCurrentScale (scale) {
  406. this.newScale = scale
  407. },
  408. openElement (dataElement) {
  409. this.activeElements[dataElement] = true
  410. },
  411. closeElement (dataElement) {
  412. this.activeElements[dataElement] = false
  413. },
  414. toggleElement (dataElement) {
  415. if (this.activeElements[dataElement]) {
  416. this.closeElement(dataElement)
  417. } else {
  418. this.openElement(dataElement)
  419. }
  420. if (dataElement === 'signCreatePanel' && this.activeElements[dataElement]) {
  421. this.setActiveSignWay('trackpad')
  422. }
  423. },
  424. setActiveElementTab (dataElement, tab) {
  425. this.activeElementsTab[dataElement] = tab
  426. },
  427. toggleActiveStickNote () {
  428. this.activeStickNote = !this.activeStickNote
  429. },
  430. closeActiveStickNote () {
  431. this.activeStickNote = false
  432. },
  433. toggleActiveMeasure () {
  434. this.activeActiveMeasure = !this.activeActiveMeasure
  435. },
  436. closeActiveMeasure () {
  437. this.activeActiveMeasure = false
  438. },
  439. toggleActiveHand (value) {
  440. this.activeHand = value
  441. },
  442. closeActiveHand () {
  443. this.activeHand = false
  444. },
  445. setSearchStatus (value) {
  446. this.searchStatus = value
  447. },
  448. setActiceToolMode (mode) {
  449. this.toolMode = mode
  450. this.activeElements['stampPanel'] = false
  451. this.activeElements['linkPanel'] = false
  452. this.activeElements['editTextPanel'] = false
  453. core.setToolMode(mode)
  454. },
  455. setDownloading (boolean) {
  456. this.downloading = boolean
  457. },
  458. setDownloadError (text) {
  459. this.downloadError = text
  460. },
  461. setActiveSignWay (way) {
  462. this.activeElementsTab['signPanelTab'] = way
  463. if (this.activeElementsTab['signPanelTab'] === 'trackpad') {
  464. core.handleSign('create')
  465. }
  466. },
  467. setPopoverChanged (bool) {
  468. this.popoverChanged = bool
  469. },
  470. setCompareStatus (string) {
  471. this.compareStatus = string
  472. },
  473. setUpload (bool) {
  474. this.upload = bool
  475. },
  476. setUploadLoading (bool) {
  477. this.uploadLoading = bool
  478. },
  479. setCompareMode (mode) {
  480. this.compareMode = mode
  481. }
  482. }
  483. })