accessibility.vue 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. <template>
  2. <header
  3. v-if="ariaSettings.isCompActive"
  4. class="accessibility"
  5. >
  6. <template
  7. v-if="ariaSettings.isCursorCrosshair"
  8. >
  9. <div
  10. class="crosshair-h aria-control-target aria-inverse-theme"
  11. :style="{top: crosshairPosition.y + 'px'}"
  12. />
  13. <div
  14. class="crosshair-v aria-control-target aria-inverse-theme"
  15. :style="{left: crosshairPosition.x + 'px'}"
  16. />
  17. </template>
  18. <div
  19. v-if="ariaSettings.isMagnifying"
  20. class="mignify-area"
  21. >
  22. <div class="text-wrapper">
  23. <p>
  24. {{ hoverElemDisc + hoverElemContent }}
  25. </p>
  26. </div>
  27. <button
  28. type="button"
  29. @click="onClickMagnifier"
  30. >
  31. <img
  32. :src="assetUrls.closeMagnifyArea"
  33. alt="close magnify area"
  34. >
  35. </button>
  36. </div>
  37. <menu
  38. v-show="ariaSettings.menuMode === 'old'"
  39. class="old-mode-menu"
  40. >
  41. <li>
  42. <button
  43. type="button"
  44. @click="onClickReset"
  45. >
  46. <img
  47. :src="assetUrls.reset"
  48. alt="reset"
  49. >
  50. <span>Reset</span>
  51. </button>
  52. </li>
  53. <li>
  54. <button
  55. type="button"
  56. @click="onClickMute"
  57. >
  58. <img
  59. :src="ariaSettings.isMuted ? assetUrls.muteActive : assetUrls.mute"
  60. alt="mute"
  61. >
  62. <span>Mute</span>
  63. </button>
  64. </li>
  65. <li>
  66. <button
  67. type="button"
  68. @click="onClickSpeechRate"
  69. >
  70. <img
  71. :src="(ariaSettings.speechRateLevel === 3) ? assetUrls.speechRate : assetUrls.speechRateActive"
  72. alt="speech rate"
  73. >
  74. <span>speech <br> rate</span>
  75. </button>
  76. </li>
  77. <li>
  78. <button
  79. type="button"
  80. @click="onClickScreenReaderMode"
  81. >
  82. <img
  83. :src="(ariaSettings.readMode === 'point') ? assetUrls.screenReaderMode : assetUrls.screenReaderModeActive"
  84. alt="screen reader"
  85. >
  86. <span>screen <br> reader</span>
  87. </button>
  88. </li>
  89. <li>
  90. <button
  91. type="button"
  92. @click="onClickColorModification"
  93. >
  94. <img
  95. :src="assetUrls.colorTheme"
  96. alt="color modification"
  97. >
  98. <span>color <br> modification</span>
  99. </button>
  100. </li>
  101. <li>
  102. <button
  103. type="button"
  104. @click="onClickZoomIn"
  105. >
  106. <img
  107. :src="assetUrls.zoomIn"
  108. alt="zoom in"
  109. >
  110. <span>zoom in</span>
  111. </button>
  112. </li>
  113. <li>
  114. <button
  115. type="button"
  116. @click="onClickZoomOut"
  117. >
  118. <img
  119. :src="assetUrls.zoomOut"
  120. alt="zoom out"
  121. >
  122. <span>zoom out</span>
  123. </button>
  124. </li>
  125. <li>
  126. <button
  127. type="button"
  128. @click="onClickCursorStyle"
  129. >
  130. <img
  131. :src="assetUrls.cursorStyle"
  132. alt="cursor style"
  133. >
  134. <span>cursor <br> style</span>
  135. </button>
  136. </li>
  137. <li>
  138. <button
  139. type="button"
  140. @click="onClickCrossCursor"
  141. >
  142. <img
  143. :src="assetUrls.crossCursor"
  144. alt="cross cursor"
  145. >
  146. <span>cross <br> cursor</span>
  147. </button>
  148. </li>
  149. <li>
  150. <button
  151. type="button"
  152. @click="onClickMagnifier"
  153. >
  154. <img
  155. :src="assetUrls.magnifier"
  156. alt="magnifier"
  157. >
  158. <span>magnifier</span>
  159. </button>
  160. </li>
  161. <li>
  162. <button
  163. type="button"
  164. @click="onClickHelp"
  165. >
  166. <img
  167. :src="assetUrls.help"
  168. alt="help"
  169. >
  170. <span>help</span>
  171. </button>
  172. </li>
  173. <li>
  174. <a
  175. ref="shortcutBtnRef"
  176. :href="shortcutFileText"
  177. download="首都博物馆.url"
  178. >
  179. <img
  180. :src="assetUrls.shotcut"
  181. alt="shotcut"
  182. >
  183. <span style="margin-top: 3px;">shortcut</span>
  184. </a>
  185. </li>
  186. <li>
  187. <button
  188. type="button"
  189. @click="onClickScreenReaderAreaEntry"
  190. >
  191. <img
  192. :src="assetUrls.screenReaderAreaEntry"
  193. alt="screen reading accessibility"
  194. >
  195. <span>Screen Reading <br> Accessibility</span>
  196. </button>
  197. </li>
  198. <li>
  199. <button
  200. type="button"
  201. @click="onClickQuit"
  202. >
  203. <img
  204. :src="assetUrls.quit"
  205. alt="quit"
  206. >
  207. <span>quit</span>
  208. </button>
  209. </li>
  210. </menu>
  211. <menu
  212. v-show="ariaSettings.menuMode === 'blind'"
  213. class="blind-mode-menu"
  214. >
  215. <div class="blind-mode-title">
  216. <h5>Intelligent blind guide</h5>
  217. <div class="splitter-line" />
  218. <h5>Regional guidelines</h5>
  219. </div>
  220. <li
  221. class="text-button"
  222. >
  223. <button
  224. type="button"
  225. >
  226. <div class="button-name">
  227. Navigation
  228. <br>
  229. area (1)
  230. </div>
  231. <div class="button-shortcut">
  232. Alt+1
  233. </div>
  234. </button>
  235. </li>
  236. <li
  237. class="text-button"
  238. >
  239. <button
  240. type="button"
  241. >
  242. <div class="button-name">
  243. Window
  244. <br>
  245. area (3)
  246. </div>
  247. <div class="button-shortcut">
  248. Alt+2
  249. </div>
  250. </button>
  251. </li>
  252. <li
  253. class="text-button"
  254. >
  255. <button
  256. type="button"
  257. >
  258. <div class="button-name">
  259. Interaction
  260. <br>
  261. area (1)
  262. </div>
  263. <div class="button-shortcut">
  264. Alt+3
  265. </div>
  266. </button>
  267. </li>
  268. <li
  269. class="image-button"
  270. >
  271. <button
  272. type="button"
  273. @click="onClickMute"
  274. >
  275. <img
  276. :src="ariaSettings.isMuted ? assetUrls.muteActive : assetUrls.mute"
  277. alt="mute"
  278. >
  279. <span>Mute</span>
  280. </button>
  281. </li>
  282. <li
  283. class="image-button"
  284. >
  285. <button
  286. type="button"
  287. @click="onClickHelp"
  288. >
  289. <img
  290. :src="assetUrls.help"
  291. alt="help"
  292. >
  293. <span>Help</span>
  294. </button>
  295. </li>
  296. <li
  297. class="image-button"
  298. >
  299. <button
  300. type="button"
  301. @click="onClickMagnifier"
  302. >
  303. <img
  304. :src="assetUrls.magnifier"
  305. alt="magnifier"
  306. >
  307. <span>Magnifier</span>
  308. </button>
  309. </li>
  310. <li
  311. class="image-button"
  312. >
  313. <button
  314. type="button"
  315. @click="onClickElderlyServicesAreaEntry"
  316. >
  317. <img
  318. :src="assetUrls.elderlyServicesAreaEntry"
  319. alt="elderly services"
  320. >
  321. <span>Elderly services</span>
  322. </button>
  323. </li>
  324. <li
  325. class="image-button"
  326. >
  327. <button
  328. type="button"
  329. @click="onClickQuit"
  330. >
  331. <img
  332. :src="assetUrls.quit"
  333. alt="quit"
  334. >
  335. <span>Quit</span>
  336. </button>
  337. </li>
  338. </menu>
  339. </header>
  340. </template>
  341. <script>
  342. import utils from "/src/utils.js"
  343. import bigCursor from '/src/assets/images/accessibility/big-cursor.cur'
  344. import "/src/assets/css/ariaGlobalStyle.less"
  345. import assetUrls from '/src/assets/images/accessibility/index.js'
  346. const speechRateFactors = [
  347. 0.75,
  348. 1,
  349. 1.25,
  350. ]
  351. const themeList = [
  352. 'default',
  353. 'white',
  354. 'blue',
  355. 'yellow',
  356. 'black',
  357. ]
  358. const zoomFactors = [
  359. 1,
  360. 1.1,
  361. 1.2,
  362. 1.3,
  363. 1.4,
  364. 1.5,
  365. 1.6,
  366. 1.7,
  367. 1.8,
  368. 1.9,
  369. 2,
  370. ]
  371. const defaultAriaSettings = {
  372. isCompActive: false, //是否显示无障碍功能菜单
  373. menuMode: 'old', // 'old', 'blind'
  374. isMuted: false,
  375. speechRateLevel: 1,
  376. readMode: 'point', // 'point'指读, 'continue'连读
  377. themeIdx: 0,
  378. zoomLevel: 0,
  379. isBigCursor: false,
  380. isCursorCrosshair: false,
  381. isMagnifying: false,
  382. }
  383. export default {
  384. data() {
  385. return {
  386. assetUrls,
  387. ariaSettings: defaultAriaSettings,
  388. crosshairPosition: {
  389. x: -100,
  390. y: -100,
  391. },
  392. hoverElemDisc: '',
  393. hoverElemContent: '',
  394. continueReadTimeoutId: null,
  395. continueReadTaskId: null,
  396. continueReadIteratorStoper: null,
  397. shortcutFileText: 'data:text/plain;charset=utf-8,' + encodeURIComponent(`
  398. [{000214A0-0000-0000-C000-000000000046}]
  399. Prop3=19,2
  400. [InternetShortcut]
  401. IDList=
  402. URL=${this.$homePageUrl}
  403. `),
  404. audioPlayer: null,
  405. }
  406. },
  407. watch: {
  408. ariaSettings: {
  409. handler(v) {
  410. let storedSettings = localStorage.getItem('ariaSettings')
  411. if (storedSettings) {
  412. storedSettings = JSON.parse(storedSettings)
  413. if (utils.isSameObject(storedSettings, v)) {
  414. return
  415. }
  416. }
  417. localStorage.setItem('ariaSettings', JSON.stringify(v))
  418. },
  419. deep: true
  420. },
  421. 'ariaSettings.isCompActive': {
  422. handler(v) {
  423. if (v) {
  424. document.body.classList.add('aria-active')
  425. document.documentElement.classList.add('aria-active')
  426. this.$emit('show')
  427. } else {
  428. this.onClickReset()
  429. for (const iterator of document.body.classList) {
  430. if (iterator === 'aria-active') {
  431. document.body.classList.remove(iterator)
  432. }
  433. }
  434. for (const iterator of document.documentElement.classList) {
  435. if (iterator === 'aria-active') {
  436. document.documentElement.classList.remove(iterator)
  437. }
  438. }
  439. this.$emit('hide')
  440. }
  441. },
  442. immediate: true,
  443. },
  444. 'ariaSettings.readMode': {
  445. handler(v) {
  446. if (v === 'point') {
  447. document.removeEventListener('mouseover', this.onMouseOverForContinueRead, {
  448. passive: true,
  449. })
  450. document.addEventListener('mouseover', this.onMouseOverForPointRead, {
  451. passive: true,
  452. })
  453. } else if (v === 'continue') {
  454. document.removeEventListener('mouseover', this.onMouseOverForPointRead, {
  455. passive: true,
  456. })
  457. document.addEventListener('mouseover', this.onMouseOverForContinueRead, {
  458. passive: true,
  459. })
  460. }
  461. },
  462. immediate: true
  463. },
  464. 'ariaSettings.themeIdx': {
  465. handler() {
  466. this.addThemeClassToNode()
  467. },
  468. immediate: true,
  469. },
  470. 'ariaSettings.zoomLevel': {
  471. handler() {
  472. this.zoomPage()
  473. },
  474. immediate: true,
  475. },
  476. 'ariaSettings.isBigCursor': {
  477. handler(v) {
  478. if (v) {
  479. const styleNode = document.createElement("style")
  480. styleNode.type = 'text/css'
  481. styleNode.id = 'aria-big-cursor-style-node'
  482. styleNode.innerHTML = `* {cursor: url(${bigCursor}), auto !important}`
  483. document.head.appendChild(styleNode)
  484. } else {
  485. const toRemove = document.getElementById('aria-big-cursor-style-node')
  486. if (toRemove) {
  487. document.head.removeChild(toRemove)
  488. }
  489. }
  490. },
  491. immediate: true,
  492. },
  493. 'ariaSettings.isCursorCrosshair': {
  494. handler(v) {
  495. if (v) {
  496. document.addEventListener('mousemove', this.onMouseMoveForCrosshair, {
  497. passive: true,
  498. })
  499. this.$nextTick(() => {
  500. this.addThemeClassToNode()
  501. })
  502. } else {
  503. document.removeEventListener('mousemove', this.onMouseMoveForCrosshair, {
  504. passive: true,
  505. })
  506. }
  507. },
  508. immediate: true,
  509. },
  510. 'ariaSettings.isMagnifying': {
  511. handler(v) {
  512. if (v) {
  513. document.body.classList.add('aria-magnifying')
  514. } else {
  515. for (const iterator of document.body.classList) {
  516. if (iterator === 'aria-magnifying') {
  517. document.body.classList.remove(iterator)
  518. }
  519. }
  520. }
  521. },
  522. immediate: true,
  523. },
  524. },
  525. created() {
  526. this.loadStoredSettings()
  527. // 在同一个域的多个页面间做同步
  528. window.addEventListener('storage', this.loadStoredSettings, {
  529. passive: true,
  530. })
  531. document.addEventListener('keydown', this.keyEventHandler, {
  532. passive: true,
  533. })
  534. document.addEventListener('focusin', this.onFocusIn, {
  535. passive: true,
  536. })
  537. this.$eventBus.$on('request-read', (text) => {
  538. console.log('无障碍组件收到request-read消息:', text);
  539. this.planToPlayAudio('', text)
  540. })
  541. },
  542. destroyed() {
  543. window.removeEventListener('storage', this.loadStoredSettings, {
  544. passive: true,
  545. }),
  546. document.removeEventListener('keydown', this.keyEventHandler, {
  547. passive: true,
  548. })
  549. document.removeEventListener('focusin', this.onFocusIn, {
  550. passive: true,
  551. })
  552. document.removeEventListener('mouseover', this.onMouseOverForContinueRead, {
  553. passive: true,
  554. })
  555. document.removeEventListener('mouseover', this.onMouseOverForPointRead, {
  556. passive: true,
  557. })
  558. },
  559. methods: {
  560. planToPlayAudio: utils.debounce(function(taskId, text = '') {
  561. let XHR = new XMLHttpRequest()
  562. const that = this
  563. XHR.onreadystatechange = function() {
  564. if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
  565. const res = JSON.parse(this.response)
  566. if (that.audioPlayer && !that.audioPlayer.ended) {
  567. that.audioPlayer.pause()
  568. }
  569. that.audioPlayer = new Audio('http://192.168.0.245:8008' + res.msg)
  570. that.audioPlayer.muted = that.ariaSettings.isMuted
  571. that.audioPlayer.playbackRate = speechRateFactors[that.ariaSettings.speechRateLevel]
  572. that.audioPlayer.oncanplaythrough = () => {
  573. that.audioPlayer.play()
  574. }
  575. that.audioPlayer.onended = () => {
  576. that.$emit('audio-end', taskId)
  577. }
  578. that.audioPlayer.onerror = (e) => {
  579. console.error('audio error!', e)
  580. that.$emit('audio-error', taskId)
  581. }
  582. that.audioPlayer.onabort = () => {
  583. that.$emit('audio-abort', taskId)
  584. }
  585. }
  586. }
  587. XHR.open("POST", "http://192.168.0.245:8008/api/tts/toMp3")
  588. XHR.setRequestHeader("Content-Type", "application/json;charset=UTF-8")
  589. XHR.send(JSON.stringify({
  590. content: text || this.hoverElemDisc + this.hoverElemContent
  591. }))
  592. }, 500),
  593. keyEventHandler(e) {
  594. if (e.repeat) {
  595. return
  596. }
  597. if (e.key === "?" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  598. if (this.ariaSettings.isCompActive) {
  599. this.onClickHelp()
  600. }
  601. } else if (e.key === "Q" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  602. if (this.ariaSettings.isCompActive) {
  603. this.onClickQuit()
  604. }
  605. } else if (e.key === "!" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  606. if (this.ariaSettings.isCompActive) {
  607. this.onClickReset()
  608. }
  609. } else if (e.key === "@" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  610. if (this.ariaSettings.isCompActive) {
  611. this.onClickMute()
  612. }
  613. } else if (e.key === "#" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  614. if (this.ariaSettings.isCompActive) {
  615. this.onClickSpeechRate()
  616. }
  617. } else if (e.key === "$" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  618. if (this.ariaSettings.isCompActive) {
  619. this.onClickScreenReaderMode()
  620. }
  621. } else if (e.key === "%" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  622. if (this.ariaSettings.isCompActive) {
  623. this.onClickColorModification()
  624. }
  625. } else if (e.key === "^" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  626. if (this.ariaSettings.isCompActive) {
  627. this.onClickZoomIn()
  628. }
  629. } else if (e.key === "&" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  630. if (this.ariaSettings.isCompActive) {
  631. this.onClickZoomOut()
  632. }
  633. } else if (e.key === "*" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  634. if (this.ariaSettings.isCompActive) {
  635. this.onClickCursorStyle()
  636. }
  637. } else if (e.key === "(" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  638. if (this.ariaSettings.isCompActive) {
  639. this.onClickCrossCursor()
  640. }
  641. } else if (e.key === ")" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  642. if (this.ariaSettings.isCompActive) {
  643. if (this.ariaSettings.menuMode === 'old') {
  644. this.onClickScreenReaderAreaEntry()
  645. } else if (this.ariaSettings.menuMode === 'blind') {
  646. this.onClickElderlyServicesAreaEntry()
  647. }
  648. }
  649. } else if (e.key === "D" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  650. if (this.ariaSettings.isCompActive) {
  651. this.$refs['shortcutBtnRef'].click()
  652. }
  653. } else if (e.key === "N" && !e.altKey && !e.ctrlKey && e.shiftKey) {
  654. if (this.ariaSettings.isCompActive) {
  655. this.onClickMagnifier()
  656. }
  657. } else if (e.key === "1" && e.altKey && !e.ctrlKey && !e.shiftKey) {
  658. const navigationArea = document.getElementById('navigation-area')
  659. if (navigationArea) {
  660. navigationArea.focus()
  661. }
  662. } else if (e.key === "2" && e.altKey && !e.ctrlKey && !e.shiftKey) {
  663. const viewportArea = document.getElementById('viewport-area')
  664. if (viewportArea) {
  665. viewportArea.focus()
  666. }
  667. } else if (e.key === "3" && e.altKey && !e.ctrlKey && !e.shiftKey) {
  668. const interactiveArea = document.getElementById('interactive-area')
  669. if (interactiveArea) {
  670. interactiveArea.focus()
  671. }
  672. }
  673. },
  674. loadStoredSettings() {
  675. const settings = localStorage.getItem('ariaSettings')
  676. if (settings) {
  677. this.ariaSettings = JSON.parse(settings)
  678. }
  679. },
  680. zoomPage() {
  681. let styleNode = document.getElementById('aria-zoom-style-node')
  682. if (!styleNode) {
  683. styleNode = document.createElement("style")
  684. styleNode.type = 'text/css'
  685. styleNode.id = 'aria-zoom-style-node'
  686. document.head.appendChild(styleNode)
  687. }
  688. styleNode.innerHTML = `
  689. .aria-control-target {
  690. transform: scale(${zoomFactors[this.ariaSettings.zoomLevel]});
  691. transform-origin: top left;
  692. }
  693. .aria-no-zoom {
  694. transform: scale(${1 / zoomFactors[this.ariaSettings.zoomLevel]});
  695. transform-origin: top left;
  696. }
  697. `
  698. },
  699. addThemeClassToNode() {
  700. this.$nextTick(() => {
  701. const controlTargetNodeList = [...document.getElementsByClassName('aria-control-target')]
  702. for (const node of controlTargetNodeList) {
  703. for (const iterator of node.classList) {
  704. if (iterator.indexOf('aria-theme-') > -1) {
  705. node.classList.remove(iterator)
  706. }
  707. }
  708. node.classList.add(`aria-theme-${themeList[this.ariaSettings.themeIdx]}`)
  709. }
  710. })
  711. },
  712. onMouseMoveForCrosshair(e) {
  713. this.crosshairPosition.x = e.clientX
  714. this.crosshairPosition.y = e.clientY
  715. },
  716. onMouseOverForPointRead(e) {
  717. if (!this.ariaSettings.isCompActive) {
  718. return
  719. }
  720. const extractedText = utils.extractTextForMagnify(e)
  721. if (extractedText) {
  722. this.hoverElemDisc = extractedText.elemDisc
  723. this.hoverElemContent = extractedText.elemContent
  724. this.planToPlayAudio()
  725. }
  726. },
  727. onMouseOverForContinueRead(e) {
  728. if (!this.ariaSettings.isCompActive) {
  729. return
  730. }
  731. const extractedText = utils.extractTextForMagnify(e)
  732. if (extractedText) {
  733. this.hoverElemDisc = extractedText.elemDisc
  734. this.hoverElemContent = extractedText.elemContent
  735. clearTimeout(this.continueReadTimeoutId)
  736. this.continueReadTimeoutId = setTimeout(() => {
  737. this.continueReadIteratorStoper && this.continueReadIteratorStoper()
  738. if (this.ariaSettings.readMode !== 'continue') {
  739. return
  740. }
  741. const continueReadTaskId = (new Date).getTime()
  742. this.continueReadTaskId = continueReadTaskId
  743. utils.iterateOnFocusableNode(e.path[0], (node) => {
  744. return new Promise((resolve, reject) => {
  745. this.continueReadIteratorStoper = reject
  746. this.$once('audio-end', (taskId) => {
  747. if (taskId === continueReadTaskId) {
  748. resolve()
  749. }
  750. })
  751. this.$once('audio-error', (taskId) => {
  752. if (taskId === continueReadTaskId) {
  753. resolve()
  754. }
  755. })
  756. this.$once('audio-abort', (taskId) => {
  757. if (taskId === continueReadTaskId) {
  758. resolve()
  759. }
  760. })
  761. })
  762. })
  763. }, 1000)
  764. }
  765. },
  766. onFocusIn(e) {
  767. if (!this.ariaSettings.isCompActive) {
  768. return
  769. }
  770. const extractedText = utils.extractTextForMagnify(e)
  771. if (extractedText) {
  772. this.hoverElemDisc = extractedText.elemDisc
  773. this.hoverElemContent = extractedText.elemContent
  774. this.planToPlayAudio(this.continueReadTaskId)
  775. }
  776. },
  777. onClickReset() {
  778. const copy = { ...defaultAriaSettings }
  779. copy.isCompActive = this.ariaSettings.isCompActive
  780. this.ariaSettings = copy
  781. },
  782. onClickMute() {
  783. this.ariaSettings.isMuted = !this.ariaSettings.isMuted
  784. if (this.audioPlayer) {
  785. this.audioPlayer.muted = this.ariaSettings.isMuted
  786. }
  787. },
  788. onClickSpeechRate() {
  789. this.ariaSettings.speechRateLevel++
  790. if (this.ariaSettings.speechRateLevel === speechRateFactors.length) {
  791. this.ariaSettings.speechRateLevel = 0
  792. }
  793. if (this.audioPlayer) {
  794. this.audioPlayer.playbackRate = speechRateFactors[this.ariaSettings.speechRateLevel]
  795. }
  796. },
  797. onClickScreenReaderMode() {
  798. if (this.ariaSettings.readMode === 'point') {
  799. this.ariaSettings.readMode = 'continue'
  800. } else if (this.ariaSettings.readMode === 'continue') {
  801. this.ariaSettings.readMode = 'point'
  802. }
  803. },
  804. onClickColorModification() {
  805. this.ariaSettings.themeIdx++
  806. if (this.ariaSettings.themeIdx === themeList.length) {
  807. this.ariaSettings.themeIdx = 0
  808. }
  809. },
  810. onClickZoomIn() {
  811. if (this.ariaSettings.zoomLevel === zoomFactors.length - 1) {
  812. return
  813. }
  814. this.ariaSettings.zoomLevel++
  815. },
  816. onClickZoomOut() {
  817. if (this.ariaSettings.zoomLevel === 0) {
  818. return
  819. }
  820. this.ariaSettings.zoomLevel--
  821. },
  822. onClickCursorStyle() {
  823. this.ariaSettings.isBigCursor = !this.ariaSettings.isBigCursor
  824. },
  825. onClickCrossCursor() {
  826. this.ariaSettings.isCursorCrosshair = !this.ariaSettings.isCursorCrosshair
  827. },
  828. onClickMagnifier() {
  829. this.ariaSettings.isMagnifying = !this.ariaSettings.isMagnifying
  830. },
  831. onClickHelp() {
  832. window.open('../help')
  833. },
  834. onClickElderlyServicesAreaEntry() {
  835. this.ariaSettings.menuMode = 'old'
  836. },
  837. onClickScreenReaderAreaEntry() {
  838. this.ariaSettings.menuMode = 'blind'
  839. },
  840. onClickQuit() {
  841. this.ariaSettings.isCompActive = false
  842. },
  843. // 供外界调用
  844. requestToShowMenu() {
  845. !this.ariaSettings.isCompActive && (this.ariaSettings.isCompActive = true)
  846. },
  847. requestToHideMenu() {
  848. this.ariaSettings.isCompActive && (this.ariaSettings.isCompActive = false)
  849. },
  850. requestToSwitchMenuShowHide() {
  851. this.ariaSettings.isCompActive = !this.ariaSettings.isCompActive
  852. },
  853. }
  854. }
  855. </script>
  856. <style lang="less" scoped>
  857. @import '/src/assets/css/common.less';
  858. li {
  859. list-style: none;
  860. }
  861. button {
  862. border: none;
  863. background: transparent;
  864. padding: 0;
  865. &:focus {
  866. outline: 3px solid red;
  867. }
  868. }
  869. a {
  870. color: inherit;
  871. text-decoration: none;
  872. &:focus {
  873. outline: 3px solid red;
  874. }
  875. }
  876. .accessibility {
  877. color: #fff;
  878. font-size: 16px;
  879. font-family: SourceHanSansCN-Bold-GBpc-EUC-H;
  880. line-height: 19px;
  881. background-color: #36584C;
  882. height: @accessibility-menu-height;
  883. position: fixed;
  884. top: 0;
  885. width: 100%;
  886. z-index: 999;
  887. .crosshair-h {
  888. position: fixed;
  889. width: 100%;
  890. height: 3px;
  891. background: blue;
  892. transform: translateY(-50%);
  893. pointer-events: none;
  894. z-index: 10;
  895. }
  896. .crosshair-v {
  897. position: fixed;
  898. height: 100vh;
  899. width: 3px;
  900. background: blue;
  901. transform: translateX(-50%);
  902. pointer-events: none;
  903. z-index: 10;
  904. }
  905. .mignify-area {
  906. position: fixed;
  907. height: @magnify-area-height;
  908. width: 100%;
  909. bottom: 0;
  910. background: #fff;
  911. z-index: 1;
  912. display: flex;
  913. .text-wrapper {
  914. height: @magnify-area-height;
  915. line-height: @magnify-area-height;
  916. width: 1px;
  917. flex: 1 0 auto;
  918. overflow: auto;
  919. text-align: center;
  920. p {
  921. vertical-align: middle;
  922. display: inline-block;
  923. color: #000;
  924. font-size: 72px;
  925. font-family: Source Han Sans CN;
  926. font-weight: 800;
  927. line-height: 86px;
  928. }
  929. }
  930. button {
  931. width: 199px;
  932. height: 100%;
  933. flex: 0 0 auto;
  934. }
  935. }
  936. .old-mode-menu {
  937. display: flex;
  938. justify-content: center;
  939. height: 100%;
  940. li {
  941. button, a {
  942. box-sizing: border-box;
  943. color: white;
  944. height: 100%;
  945. padding-top: 10px;
  946. width: @accessibility-menu-height;
  947. display: flex;
  948. flex-direction: column;
  949. align-items: center;
  950. &:hover {
  951. background-color: #4D2128;
  952. }
  953. img {
  954. width: 50px;
  955. height: 50px;
  956. }
  957. span {
  958. display: block;
  959. margin-top: 5px;
  960. }
  961. }
  962. }
  963. }
  964. .blind-mode-menu {
  965. display: flex;
  966. justify-content: center;
  967. height: 100%;
  968. .blind-mode-title {
  969. width: 231px;
  970. height: 80px;
  971. background: #753641;
  972. border-radius: 20px;
  973. border: 2px solid rgb(136, 67, 79);
  974. text-align: center;
  975. margin-top: 12px;
  976. margin-right: 30px;
  977. h5 {
  978. font-size: 18px;
  979. line-height: 36px;
  980. }
  981. .splitter-line {
  982. width: 208px;
  983. height: 0px;
  984. border: 1px solid rgb(136, 67, 79);
  985. margin: 0 auto;
  986. }
  987. }
  988. li.text-button:nth-of-type(3) {
  989. margin-right: 100px;
  990. }
  991. li.text-button {
  992. button {
  993. width: 125px;
  994. color: #fff;
  995. display: flex;
  996. flex-direction: column;
  997. justify-content: center;
  998. align-items: center;
  999. height: 100%;
  1000. &:hover {
  1001. background-color: #4D2128;
  1002. }
  1003. .button-name {
  1004. font-size: 14px;
  1005. line-height: 21px;
  1006. margin-bottom: 6px;
  1007. }
  1008. .button-shortcut {
  1009. font-size: 16px;
  1010. }
  1011. }
  1012. }
  1013. li.image-button {
  1014. button {
  1015. color: white;
  1016. height: 100%;
  1017. padding-top: 10px;
  1018. width: @accessibility-menu-height;
  1019. display: flex;
  1020. flex-direction: column;
  1021. align-items: center;
  1022. &:hover {
  1023. background-color: #4D2128;
  1024. }
  1025. img {
  1026. width: 50px;
  1027. height: 50px;
  1028. }
  1029. span {
  1030. display: block;
  1031. margin-top: 5px;
  1032. }
  1033. }
  1034. }
  1035. }
  1036. }
  1037. </style>