global-events.uvue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view style="flex: 1">
  4. <!-- #endif -->
  5. <page-head title="触摸方块测试相关事件"></page-head>
  6. <view class="uni-padding-wrap uni-common-mt container">
  7. <view class="target" id="touch-target" @touchstart="onTouchStart" @touchcancel="onTouchCancel"
  8. @touchmove="onTouchMove" @touchend="onTouchEnd"></view>
  9. <view class="target" id="longpress-target" @tap="onTap" @click="onClick" @longpress="onLongPress"></view>
  10. <view v-if="touchStartEvent !== null">
  11. <text class="title1">touchStart Event: </text>
  12. <text class="title2">touches: </text>
  13. <template v-for="(touch, index) in touchStartEvent!.touches" :key="index">
  14. <text class="title3">touch[{{ index }}]:</text>
  15. <view class="uni-list-cell">
  16. <text>identifier: </text>
  17. <text id="touch-start-touch-identifier">{{
  18. touch.identifier
  19. }}</text>
  20. </view>
  21. <view class="uni-list-cell">
  22. <text>pageX: </text>
  23. <text id="touch-start-touch-page-x">{{ touch.pageX }}</text>
  24. </view>
  25. <view class="uni-list-cell">
  26. <text>pageY: </text>
  27. <text id="touch-start-touch-page-y">{{ touch.pageY }}</text>
  28. </view>
  29. <view class="uni-list-cell">
  30. <text>clientX: </text>
  31. <text id="touch-start-touch-client-x">{{ touch.clientX }}</text>
  32. </view>
  33. <view class="uni-list-cell">
  34. <text>clientY: </text>
  35. <text id="touch-start-touch-client-y">{{ touch.clientY }}</text>
  36. </view>
  37. <view class="uni-list-cell">
  38. <text>screenX: </text>
  39. <text id="touch-start-touch-screen-x">{{ touch.screenX }}</text>
  40. </view>
  41. <view class="uni-list-cell">
  42. <text>screenY: </text>
  43. <text id="touch-start-touch-screen-y">{{ touch.screenY }}</text>
  44. </view>
  45. </template>
  46. <text class="title2 uni-common-mt">changedTouches: </text>
  47. <template v-for="(touch, index) in touchStartEvent!.changedTouches" :key="index">
  48. <text class="title3">touch[{{ index }}]:</text>
  49. <view class="uni-list-cell">
  50. <text>identifier: </text>
  51. <text id="touch-start-changed-touch-identifier">{{
  52. touch.identifier
  53. }}</text>
  54. </view>
  55. <view class="uni-list-cell">
  56. <text>pageX: </text>
  57. <text id="touch-start-changed-touch-page-x">{{ touch.pageX }}</text>
  58. </view>
  59. <view class="uni-list-cell">
  60. <text>pageY: </text>
  61. <text id="touch-start-changed-touch-page-y">{{ touch.pageY }}</text>
  62. </view>
  63. <view class="uni-list-cell">
  64. <text>clientX: </text>
  65. <text id="touch-start-changed-touch-client-x">{{
  66. touch.clientX
  67. }}</text>
  68. </view>
  69. <view class="uni-list-cell">
  70. <text>clientY: </text>
  71. <text id="touch-start-changed-touch-client-y">{{
  72. touch.clientY
  73. }}</text>
  74. </view>
  75. <view class="uni-list-cell">
  76. <text>screenX: </text>
  77. <text id="touch-start-changed-touch-screen-x">{{
  78. touch.screenX
  79. }}</text>
  80. </view>
  81. <view class="uni-list-cell">
  82. <text>screenY: </text>
  83. <text id="touch-start-changed-touch-screen-y">{{
  84. touch.screenY
  85. }}</text>
  86. </view>
  87. </template>
  88. </view>
  89. <view v-if="touchCancelEvent !== null">
  90. <text class="title1">touchCancel Event: </text>
  91. <text class="title2">touches: </text>
  92. <template v-for="(touch, index) in touchCancelEvent!.touches" :key="index">
  93. <text class="title3">touch[{{ index }}]:</text>
  94. <view class="uni-list-cell">
  95. <text>identifier: </text>
  96. <text id="touch-cancel-touch-identifier">{{
  97. touch.identifier
  98. }}</text>
  99. </view>
  100. <view class="uni-list-cell">
  101. <text>pageX: </text>
  102. <text id="touch-cancel-touch-page-x">{{ touch.pageX }}</text>
  103. </view>
  104. <view class="uni-list-cell">
  105. <text>pageY: </text>
  106. <text id="touch-cancel-touch-page-y">{{ touch.pageY }}</text>
  107. </view>
  108. <view class="uni-list-cell">
  109. <text>clientX: </text>
  110. <text id="touch-cancel-touch-client-x">{{ touch.clientX }}</text>
  111. </view>
  112. <view class="uni-list-cell">
  113. <text>clientY: </text>
  114. <text id="touch-cancel-touch-client-y">{{ touch.clientY }}</text>
  115. </view>
  116. <view class="uni-list-cell">
  117. <text>screenX: </text>
  118. <text id="touch-cancel-touch-screen-x">{{ touch.screenX }}</text>
  119. </view>
  120. <view class="uni-list-cell">
  121. <text>screenY: </text>
  122. <text id="touch-cancel-touch-screen-y">{{ touch.screenY }}</text>
  123. </view>
  124. </template>
  125. <text class="title2 uni-common-mt">changedTouches: </text>
  126. <template v-for="(touch, index) in touchCancelEvent!.changedTouches" :key="index">
  127. <text class="title3">touch[{{ index }}]:</text>
  128. <view class="uni-list-cell">
  129. <text>identifier: </text>
  130. <text id="touch-cancel-changed-touch-identifier">{{
  131. touch.identifier
  132. }}</text>
  133. </view>
  134. <view class="uni-list-cell">
  135. <text>pageX: </text>
  136. <text id="touch-cancel-changed-touch-page-x">{{
  137. touch.pageX
  138. }}</text>
  139. </view>
  140. <view class="uni-list-cell">
  141. <text>pageY: </text>
  142. <text id="touch-cancel-changed-touch-page-y">{{
  143. touch.pageY
  144. }}</text>
  145. </view>
  146. <view class="uni-list-cell">
  147. <text>clientX: </text>
  148. <text id="touch-cancel-changed-touch-client-x">{{
  149. touch.clientX
  150. }}</text>
  151. </view>
  152. <view class="uni-list-cell">
  153. <text>clientY: </text>
  154. <text id="touch-cancel-changed-touch-client-y">{{
  155. touch.clientY
  156. }}</text>
  157. </view>
  158. <view class="uni-list-cell">
  159. <text>screenX: </text>
  160. <text id="touch-cancel-changed-touch-screen-x">{{
  161. touch.screenX
  162. }}</text>
  163. </view>
  164. <view class="uni-list-cell">
  165. <text>screenY: </text>
  166. <text id="touch-cancel-changed-touch-screen-y">{{
  167. touch.screenY
  168. }}</text>
  169. </view>
  170. </template>
  171. </view>
  172. <view v-if="touchMoveEvent !== null">
  173. <text class="title1">touchMove Event: </text>
  174. <text class="title2">touches: </text>
  175. <template v-for="(touch, index) in touchMoveEvent!.touches" :key="index">
  176. <text class="title3">touch[{{ index }}]:</text>
  177. <view class="uni-list-cell">
  178. <text>identifier: </text>
  179. <text id="touch-move-touch-identifier">{{ touch.identifier }}</text>
  180. </view>
  181. <view class="uni-list-cell">
  182. <text>pageX: </text>
  183. <text id="touch-move-touch-page-x">{{ touch.pageX }}</text>
  184. </view>
  185. <view class="uni-list-cell">
  186. <text>pageY: </text>
  187. <text id="touch-move-touch-page-y">{{ touch.pageY }}</text>
  188. </view>
  189. <view class="uni-list-cell">
  190. <text>clientX: </text>
  191. <text id="touch-move-touch-client-x">{{ touch.clientX }}</text>
  192. </view>
  193. <view class="uni-list-cell">
  194. <text>clientY: </text>
  195. <text id="touch-move-touch-client-y">{{ touch.clientY }}</text>
  196. </view>
  197. <view class="uni-list-cell">
  198. <text>screenX: </text>
  199. <text id="touch-move-touch-screen-x">{{ touch.screenX }}</text>
  200. </view>
  201. <view class="uni-list-cell">
  202. <text>screenY: </text>
  203. <text id="touch-move-touch-screen-y">{{ touch.screenY }}</text>
  204. </view>
  205. </template>
  206. <text class="title2 uni-common-mt">changedTouches: </text>
  207. <template v-for="(touch, index) in touchMoveEvent!.changedTouches" :key="index">
  208. <text class="title3">touch[{{ index }}]:</text>
  209. <view class="uni-list-cell">
  210. <text>identifier: </text>
  211. <text id="touch-move-changed-touch-identifier">{{
  212. touch.identifier
  213. }}</text>
  214. </view>
  215. <view class="uni-list-cell">
  216. <text>pageX: </text>
  217. <text id="touch-move-changed-touch-page-x">{{ touch.pageX }}</text>
  218. </view>
  219. <view class="uni-list-cell">
  220. <text>pageY: </text>
  221. <text id="touch-move-changed-touch-page-y">{{ touch.pageY }}</text>
  222. </view>
  223. <view class="uni-list-cell">
  224. <text>clientX: </text>
  225. <text id="touch-move-changed-touch-client-x">{{
  226. touch.clientX
  227. }}</text>
  228. </view>
  229. <view class="uni-list-cell">
  230. <text>clientY: </text>
  231. <text id="touch-move-changed-touch-client-y">{{
  232. touch.clientY
  233. }}</text>
  234. </view>
  235. <view class="uni-list-cell">
  236. <text>screenX: </text>
  237. <text id="touch-move-changed-touch-screen-x">{{
  238. touch.screenX
  239. }}</text>
  240. </view>
  241. <view class="uni-list-cell">
  242. <text>screenY: </text>
  243. <text id="touch-move-changed-touch-screen-y">{{
  244. touch.screenY
  245. }}</text>
  246. </view>
  247. </template>
  248. </view>
  249. <view v-if="touchEndEvent !== null">
  250. <text class="title1">touchEnd Event: </text>
  251. <text class="title2">touches: </text>
  252. <template v-if="touchEndEvent!.touches.length > 0" v-for="(touch, index) in touchEndEvent!.touches"
  253. :key="index">
  254. <text class="title3">touch[{{ index }}]:</text>
  255. <view class="uni-list-cell">
  256. <text>identifier: </text>
  257. <text id="touch-end-touch-identifier">{{ touch.identifier }}</text>
  258. </view>
  259. <view class="uni-list-cell">
  260. <text>pageX: </text>
  261. <text id="touch-end-touch-page-x">{{ touch.pageX }}</text>
  262. </view>
  263. <view class="uni-list-cell">
  264. <text>pageY: </text>
  265. <text id="touch-end-touch-page-y">{{ touch.pageY }}</text>
  266. </view>
  267. <view class="uni-list-cell">
  268. <text>clientX: </text>
  269. <text id="touch-end-touch-client-x">{{ touch.clientX }}</text>
  270. </view>
  271. <view class="uni-list-cell">
  272. <text>clientY: </text>
  273. <text id="touch-end-touch-client-y">{{ touch.clientY }}</text>
  274. </view>
  275. <view class="uni-list-cell">
  276. <text>screenX: </text>
  277. <text id="touch-end-touch-screen-x">{{ touch.screenX }}</text>
  278. </view>
  279. <view class="uni-list-cell">
  280. <text>screenY: </text>
  281. <text id="touch-end-touch-screen-y">{{ touch.screenY }}</text>
  282. </view>
  283. </template>
  284. <text class="title2 uni-common-mt">changedTouches: </text>
  285. <template v-for="(touch, index) in touchEndEvent!.changedTouches" :key="index">
  286. <text class="title3">touch[{{ index }}]:</text>
  287. <view class="uni-list-cell">
  288. <text>identifier: </text>
  289. <text id="touch-end-changed-touch-identifier">{{
  290. touch.identifier
  291. }}</text>
  292. </view>
  293. <view class="uni-list-cell">
  294. <text>pageX: </text>
  295. <text id="touch-end-changed-touch-page-x">{{ touch.pageX }}</text>
  296. </view>
  297. <view class="uni-list-cell">
  298. <text>pageY: </text>
  299. <text id="touch-end-changed-touch-page-y">{{ touch.pageY }}</text>
  300. </view>
  301. <view class="uni-list-cell">
  302. <text>clientX: </text>
  303. <text id="touch-end-changed-touch-client-x">{{
  304. touch.clientX
  305. }}</text>
  306. </view>
  307. <view class="uni-list-cell">
  308. <text>clientY: </text>
  309. <text id="touch-end-changed-touch-client-y">{{
  310. touch.clientY
  311. }}</text>
  312. </view>
  313. <view class="uni-list-cell">
  314. <text>screenX: </text>
  315. <text id="touch-end-changed-touch-screen-x">{{
  316. touch.screenX
  317. }}</text>
  318. </view>
  319. <view class="uni-list-cell">
  320. <text>screenY: </text>
  321. <text id="touch-end-changed-touch-screen-y">{{
  322. touch.screenY
  323. }}</text>
  324. </view>
  325. </template>
  326. </view>
  327. <view v-if="longPressEvent !== null">
  328. <text class="title1">longPress Event: </text>
  329. <text class="title2">touches: </text>
  330. <template v-if="longPressEvent!.touches.length > 0" v-for="(touch, index) in longPressEvent!.touches"
  331. :key="index">
  332. <text class="title3">touch[{{ index }}]:</text>
  333. <view class="uni-list-cell">
  334. <text>identifier: </text>
  335. <text id="long-press-touch-identifier">{{ touch.identifier }}</text>
  336. </view>
  337. <view class="uni-list-cell">
  338. <text>pageX: </text>
  339. <text id="long-press-touch-page-x">{{ touch.pageX }}</text>
  340. </view>
  341. <view class="uni-list-cell">
  342. <text>pageY: </text>
  343. <text id="long-press-touch-page-y">{{ touch.pageY }}</text>
  344. </view>
  345. <view class="uni-list-cell">
  346. <text>clientX: </text>
  347. <text id="long-press-touch-client-x">{{ touch.clientX }}</text>
  348. </view>
  349. <view class="uni-list-cell">
  350. <text>clientY: </text>
  351. <text id="long-press-touch-client-y">{{ touch.clientY }}</text>
  352. </view>
  353. <view class="uni-list-cell">
  354. <text>screenX: </text>
  355. <text id="long-press-touch-screen-x">{{ touch.screenX }}</text>
  356. </view>
  357. <view class="uni-list-cell">
  358. <text>screenY: </text>
  359. <text id="long-press-touch-screen-y">{{ touch.screenY }}</text>
  360. </view>
  361. </template>
  362. <text class="title2 uni-common-mt">changedTouches: </text>
  363. <template v-for="(touch, index) in longPressEvent!.changedTouches" :key="index">
  364. <text class="title3">touch[{{ index }}]:</text>
  365. <view class="uni-list-cell">
  366. <text>identifier: </text>
  367. <text id="long-press-changed-touch-identifier">{{
  368. touch.identifier
  369. }}</text>
  370. </view>
  371. <view class="uni-list-cell">
  372. <text>pageX: </text>
  373. <text id="long-press-changed-touch-page-x">{{ touch.pageX }}</text>
  374. </view>
  375. <view class="uni-list-cell">
  376. <text>pageY: </text>
  377. <text id="long-press-changed-touch-page-y">{{ touch.pageY }}</text>
  378. </view>
  379. <view class="uni-list-cell">
  380. <text>clientX: </text>
  381. <text id="long-press-changed-touch-client-x">{{
  382. touch.clientX
  383. }}</text>
  384. </view>
  385. <view class="uni-list-cell">
  386. <text>clientY: </text>
  387. <text id="long-press-changed-touch-client-y">{{
  388. touch.clientY
  389. }}</text>
  390. </view>
  391. <view class="uni-list-cell">
  392. <text>screenX: </text>
  393. <text id="long-press-changed-touch-screen-x">{{
  394. touch.screenX
  395. }}</text>
  396. </view>
  397. <view class="uni-list-cell">
  398. <text>screenY: </text>
  399. <text id="long-press-changed-touch-screen-y">{{
  400. touch.screenY
  401. }}</text>
  402. </view>
  403. </template>
  404. </view>
  405. <view v-if="tapEvent !== null">
  406. <text class="title1">tap Event: </text>
  407. <view class="uni-list-cell">
  408. <text>x: </text>
  409. <text id="tap-event-x">{{ tapEvent!.x }}</text>
  410. </view>
  411. <view class="uni-list-cell">
  412. <text>y: </text>
  413. <text id="tap-event-y">{{ tapEvent!.y }}</text>
  414. </view>
  415. </view>
  416. <view v-if="clickEvent !== null">
  417. <text class="title1">click Event: </text>
  418. <view class="uni-list-cell">
  419. <text>x: </text>
  420. <text id="click-event-x">{{ clickEvent!.x }}</text>
  421. </view>
  422. <view class="uni-list-cell">
  423. <text>y: </text>
  424. <text id="click-event-y">{{ clickEvent!.y }}</text>
  425. </view>
  426. </view>
  427. </view>
  428. <!-- #ifdef APP -->
  429. </scroll-view>
  430. <!-- #endif -->
  431. </template>
  432. <script lang="uts">
  433. export default {
  434. data() {
  435. return {
  436. title: 'global-events',
  437. touchStartEvent: null as TouchEvent | null,
  438. touchCancelEvent: null as TouchEvent | null,
  439. touchMoveEvent: null as TouchEvent | null,
  440. longPressEvent: null as TouchEvent | null,
  441. touchEndEvent: null as TouchEvent | null,
  442. tapEvent: null as PointerEvent | null,
  443. clickEvent: null as PointerEvent | null,
  444. }
  445. },
  446. methods: {
  447. onTouchStart(e : TouchEvent) {
  448. this.touchStartEvent = e
  449. console.log('onTouchStart', e)
  450. },
  451. onTouchCancel(e : TouchEvent) {
  452. this.touchCancelEvent = e
  453. console.log('onTouchCancel')
  454. },
  455. onTouchMove(e : TouchEvent) {
  456. this.touchMoveEvent = e
  457. console.log('onTouchMove', e)
  458. },
  459. onLongPress(e : TouchEvent) {
  460. this.longPressEvent = e
  461. console.log('onLongPress', e)
  462. },
  463. onTouchEnd(e : TouchEvent) {
  464. this.touchEndEvent = e
  465. console.log('onTouchEnd', e)
  466. },
  467. onTap(e : PointerEvent) {
  468. this.tapEvent = e
  469. console.log('onTap', e)
  470. },
  471. onClick(e : PointerEvent) {
  472. this.clickEvent = e
  473. console.log('onClick', e)
  474. }
  475. },
  476. }
  477. </script>
  478. <style>
  479. .container {
  480. padding-bottom: 10px;
  481. }
  482. .target {
  483. margin: 20px 0 0 50px;
  484. width: 200px;
  485. height: 100px;
  486. background-color: aqua;
  487. }
  488. .title1 {
  489. margin-top: 15px;
  490. font-size: 20px;
  491. }
  492. .title2 {
  493. margin-top: 10px;
  494. font-size: 18px;
  495. }
  496. .title3 {
  497. margin-top: 5px;
  498. font-size: 16px;
  499. }
  500. </style>