dialog-page.uvue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view style="flex: 1;">
  4. <!-- #endif -->
  5. <view class="uni-padding-wrap">
  6. <view class="uni-common-mt flex-row" v-if="pageBody != null">pageBody: {
  7. top: <text id="page-body-top">{{pageBody!.top}}</text>,
  8. right: <text id="page-body-right">{{pageBody!.right}}</text>,
  9. bottom: <text id="page-body-bottom">{{pageBody!.bottom}}</text>,
  10. left: <text id="page-body-left">{{pageBody!.left}}</text>,
  11. width: <text id="page-body-width">{{pageBody!.width}}</text>,
  12. height: <text id="page-body-height">{{pageBody!.height}}</text>
  13. }
  14. </view>
  15. <view class="uni-common-mt flex-row" v-if="safeAreaInsets != null">safeAreaInsets: {
  16. top: <text id="page-safe-area-insets-top">{{safeAreaInsets!.top}}</text>,
  17. right: <text id="page-safe-area-insets-right">{{safeAreaInsets!.right}}</text>,
  18. bottom: <text id="page-safe-area-insets-bottom">{{safeAreaInsets!.bottom}}</text>,
  19. left: <text id="page-safe-area-insets-left">{{safeAreaInsets!.left}}</text>}
  20. </view>
  21. <!-- #ifdef APP-ANDROID || APP-IOS || APP-HARMONY || WEB -->
  22. <view class="uni-common-mt flex-row" v-if="width != null">width: <text id="page-width">{{width!}}</text>
  23. </view>
  24. <view class="uni-common-mt flex-row" v-if="height != null">height: <text id="page-height">{{height!}}</text>
  25. </view>
  26. <view class="uni-common-mt flex-row" v-if="statusBarHeight != null">statusBarHeight: <text id="page-statusBarHeight">{{statusBarHeight!}}</text>
  27. </view>
  28. <!-- #endif -->
  29. <button class="uni-common-mt" id="go-next-page" @click="goNextPage">
  30. go next page
  31. </button>
  32. <button class="uni-common-mt" id="open-dialog1" @click="openDialog1">
  33. open dialog 1
  34. </button>
  35. <button class="uni-common-mt" id="open-dialog1-wrong-path" @click="openDialog1WrongPath">
  36. open dialog page 1 with wrong path
  37. </button>
  38. <button class="uni-common-mt" id="go-next-page-open-dialog1" @click="goNextPageOpenDialog1">
  39. go next page & open dialog1
  40. </button>
  41. <button class="uni-common-mt" id="open-dialog1" @click="openDialog3">
  42. open dialog 3 test page style
  43. </button>
  44. <button class="uni-common-mt" id="open-dialog4" @click="openDialogWithTriggerParentHide">
  45. openDialog with triggerParentHide
  46. </button>
  47. <button class="uni-common-mt" id="open-dialog5" @click="openDialogCheckMoreAttribute">
  48. openDialog check more attribute
  49. </button>
  50. <button class="uni-common-mt" id="open-dialog5" @click="openDialogWithRelativePath">
  51. openDialog with relative path
  52. </button>
  53. <text class="uni-common-mt choose-open-animation-type-title">choose open dialogPage animationType</text>
  54. <radio-group class="choose-open-animation-type-radio-group" @change="handleOpenAnimationType">
  55. <radio class="ml-10 uni-common-mt" v-for="item in openAnimationTypeList" :key="item" :value="item"
  56. :checked="openAnimationType == item">{{ item }}
  57. </radio>
  58. </radio-group>
  59. </view>
  60. <!-- #ifdef APP -->
  61. </scroll-view>
  62. <!-- #endif -->
  63. </template>
  64. <script lang="uts">
  65. import {
  66. state,
  67. setLifeCycleNum
  68. } from '@/store/index.uts'
  69. type OpenAnimationType =
  70. 'auto' |
  71. 'none' |
  72. 'slide-in-right' |
  73. 'slide-in-left' |
  74. 'slide-in-top' |
  75. 'slide-in-bottom' |
  76. 'fade-in' |
  77. 'zoom-out' |
  78. 'zoom-fade-out'
  79. export default {
  80. data() {
  81. return {
  82. pageBody : null as UniPageBody | null,
  83. safeAreaInsets: null as UniSafeAreaInsets | null,
  84. width: null as number | null,
  85. height: null as number | null,
  86. statusBarHeight: null as number | null,
  87. jest_click_x: -1,
  88. jest_click_y: -1,
  89. openAnimationType: 'none' as OpenAnimationType,
  90. openAnimationTypeList: [
  91. 'auto',
  92. 'none',
  93. 'slide-in-right',
  94. 'slide-in-left',
  95. 'slide-in-top',
  96. 'slide-in-bottom',
  97. 'fade-in',
  98. 'zoom-out',
  99. 'zoom-fade-out'
  100. ]
  101. }
  102. },
  103. onLoad() {
  104. console.log('dialogPage parent onLoad')
  105. },
  106. onShow() {
  107. console.log('dialogPage parent onShow')
  108. setLifeCycleNum(state.lifeCycleNum + 10)
  109. },
  110. onReady() {
  111. console.log('dialogPage parent onReady')
  112. const currentPage = this.$page
  113. this.pageBody = currentPage.pageBody;
  114. this.safeAreaInsets = currentPage.safeAreaInsets
  115. // #ifdef APP-ANDROID || APP-IOS || APP-HARMONY || WEB
  116. this.width = currentPage.width
  117. this.height = currentPage.height
  118. this.statusBarHeight = currentPage.statusBarHeight
  119. // #endif
  120. },
  121. onHide() {
  122. console.log('dialogPage parent onHide')
  123. setLifeCycleNum(state.lifeCycleNum - 10)
  124. },
  125. onUnload() {
  126. console.log('dialogPage parent onUnload')
  127. },
  128. methods: {
  129. goNextPage() {
  130. uni.navigateTo({
  131. url: '/pages/API/dialog-page/next-page'
  132. })
  133. },
  134. openDialog1() {
  135. uni.openDialogPage({
  136. url: '/pages/API/dialog-page/dialog-1?name=dialog1',
  137. animationType: this.openAnimationType,
  138. success(res) {
  139. console.log('openDialogPage1 success', res)
  140. // 自动化测试
  141. setLifeCycleNum(state.lifeCycleNum + 1)
  142. },
  143. fail(err) {
  144. console.log('openDialogPage1 fail', err)
  145. setLifeCycleNum(state.lifeCycleNum - 4)
  146. },
  147. complete(res) {
  148. console.log('openDialogPage1 complete', res)
  149. // 自动化测试
  150. setLifeCycleNum(state.lifeCycleNum + 1)
  151. }
  152. })
  153. },
  154. openDialog2() {
  155. uni.openDialogPage({
  156. url: '/pages/API/dialog-page/dialog-2',
  157. animationType: this.openAnimationType,
  158. disableEscBack: true,
  159. success(res) {
  160. console.log('openDialog2 success', res)
  161. // 自动化测试
  162. setLifeCycleNum(state.lifeCycleNum + 1)
  163. },
  164. fail(err) {
  165. console.log('openDialog2 fail', err)
  166. // 自动化测试
  167. setLifeCycleNum(state.lifeCycleNum - 4)
  168. },
  169. complete(res) {
  170. console.log('openDialog2 complete', res)
  171. // 自动化测试
  172. setLifeCycleNum(state.lifeCycleNum + 1)
  173. }
  174. })
  175. },
  176. openDialog1WrongPath() {
  177. uni.openDialogPage({
  178. url: '/pages/API/dialog-page/dialog-11?name=dialog1',
  179. success(res) {
  180. console.log('openDialogPage1 success', res)
  181. // 自动化测试
  182. setLifeCycleNum(state.lifeCycleNum + 1)
  183. },
  184. fail(err) {
  185. console.log('openDialogPage1 fail', err)
  186. setLifeCycleNum(state.lifeCycleNum - 4)
  187. },
  188. complete(res) {
  189. console.log('openDialogPage1 complete', res)
  190. // 自动化测试
  191. setLifeCycleNum(state.lifeCycleNum + 1)
  192. }
  193. })
  194. },
  195. goNextPageOpenDialog1() {
  196. uni.navigateTo({
  197. url: '/pages/API/dialog-page/next-page',
  198. success() {
  199. setTimeout(() => {
  200. uni.openDialogPage({
  201. url: '/pages/API/dialog-page/dialog-1?name=dialog1',
  202. animationType: this.openAnimationType,
  203. success(res) {
  204. console.log('openDialogPage1 success', res)
  205. // 自动化测试
  206. setLifeCycleNum(state.lifeCycleNum + 1)
  207. },
  208. fail(err) {
  209. console.log('openDialogPage1 fail', err)
  210. // 自动化测试
  211. setLifeCycleNum(state.lifeCycleNum - 4)
  212. },
  213. complete(res) {
  214. console.log('openDialogPage1 complete', res)
  215. // 自动化测试
  216. setLifeCycleNum(state.lifeCycleNum + 1)
  217. }
  218. })
  219. }, 2000)
  220. }
  221. })
  222. },
  223. closeDialog() {
  224. uni.closeDialogPage({
  225. success(res) {
  226. console.log('closeDialog success', res)
  227. // 自动化测试
  228. setLifeCycleNum(state.lifeCycleNum + 1)
  229. },
  230. fail(err) {
  231. console.log('closeDialog fail', err)
  232. // 自动化测试
  233. setLifeCycleNum(state.lifeCycleNum - 4)
  234. },
  235. complete(res) {
  236. console.log('closeDialog complete', res)
  237. // 自动化测试
  238. setLifeCycleNum(state.lifeCycleNum + 1)
  239. }
  240. })
  241. },
  242. closeSpecifiedDialog(index : number) {
  243. const dialogPages = this.$page.getDialogPages()
  244. uni.closeDialogPage({
  245. dialogPage: dialogPages[index],
  246. success(res) {
  247. console.log('closeSomeOneDialog success', res)
  248. // 自动化测试
  249. setLifeCycleNum(state.lifeCycleNum + 1)
  250. },
  251. fail(err) {
  252. console.log('closeSomeOneDialog fail', err)
  253. // 自动化测试
  254. setLifeCycleNum(state.lifeCycleNum - 4)
  255. },
  256. complete(res) {
  257. console.log('closeSomeOneDialog complete', res)
  258. // 自动化测试
  259. setLifeCycleNum(state.lifeCycleNum + 1)
  260. }
  261. })
  262. },
  263. // 自动化测试
  264. openDialog4() {
  265. uni.openDialogPage({
  266. url: '/pages/API/dialog-page/dialog-4',
  267. })
  268. },
  269. openDialogWithTriggerParentHide() {
  270. uni.openDialogPage({
  271. url: `/pages/API/dialog-page/dialog-4?tag=${Date.now()}`,
  272. triggerParentHide: true,
  273. success(res) {
  274. console.log('openDialogWithTriggerParentHide success', res)
  275. // 自动化测试
  276. setLifeCycleNum(state.lifeCycleNum + 1)
  277. },
  278. fail(err) {
  279. console.log('openDialogWithTriggerParentHide fail', err)
  280. // 自动化测试
  281. setLifeCycleNum(state.lifeCycleNum - 4)
  282. },
  283. complete(res) {
  284. console.log('openDialogWithTriggerParentHide complete', res)
  285. // 自动化测试
  286. setLifeCycleNum(state.lifeCycleNum + 1)
  287. }
  288. })
  289. },
  290. openDialogCheckMoreAttribute(){
  291. uni.openDialogPage({
  292. url: '/pages/API/dialog-page/dialog-5',
  293. })
  294. },
  295. setLifeCycleNum(value : number) {
  296. setLifeCycleNum(value)
  297. },
  298. getLifeCycleNum() : number {
  299. return state.lifeCycleNum
  300. },
  301. jest_OpenDialog1() {
  302. uni.openDialogPage({
  303. url: '/pages/API/dialog-page/dialog-1?name=dialog1'
  304. })
  305. },
  306. jest_CloseDialog1() {
  307. uni.closeDialogPage({})
  308. },
  309. jest_getTapPoint() {
  310. const systemInfo = uni.getSystemInfoSync()
  311. let ratio = 1
  312. if (systemInfo.platform == 'android') {
  313. ratio = systemInfo.devicePixelRatio
  314. }
  315. this.jest_click_x = systemInfo.screenWidth / 2 * ratio
  316. this.jest_click_y = systemInfo.statusBarHeight * ratio + 10
  317. },
  318. openDialog2ForTest() {
  319. uni.openDialogPage({
  320. url: '/pages/API/dialog-page/dialog-2'
  321. });
  322. },
  323. closeDialog2ForTest() {
  324. uni.closeDialogPage({});
  325. },
  326. setPageStyleForTest(style : UTSJSONObject) {
  327. const pages = this.$page.getDialogPages();
  328. if (pages.length > 0) pages[pages.length - 1].setPageStyle(style);
  329. },
  330. setPageStyleForTest2(style : UTSJSONObject) {
  331. this.$page.setPageStyle(style);
  332. },
  333. openDialog3() {
  334. uni.openDialogPage({ url: '/pages/API/dialog-page/dialog-3', animationType: this.openAnimationType })
  335. },
  336. handleOpenAnimationType(e : RadioGroupChangeEvent) {
  337. this.openAnimationType = e.detail.value as OpenAnimationType
  338. },
  339. openDialogWithRelativePath(){
  340. uni.openDialogPage({
  341. url: './dialog-1?name=dialog1',
  342. animationType: this.openAnimationType,
  343. success(res) {
  344. console.log('openDialogPage1 success', res)
  345. // 自动化测试
  346. setLifeCycleNum(state.lifeCycleNum + 1)
  347. },
  348. fail(err) {
  349. console.log('openDialogPage1 fail', err)
  350. setLifeCycleNum(state.lifeCycleNum - 4)
  351. },
  352. complete(res) {
  353. console.log('openDialogPage1 complete', res)
  354. // 自动化测试
  355. setLifeCycleNum(state.lifeCycleNum + 1)
  356. }
  357. })
  358. },
  359. // 自动化测试
  360. getDialogPage() : UniPage | null {
  361. const dialogPages = this.$page.getDialogPages()
  362. return dialogPages.length > 0 ? dialogPages[0] : null
  363. },
  364. // 自动化测试
  365. getDialogPageRoute() : string {
  366. const dialogPage = this.getDialogPage()
  367. if(dialogPage != null){
  368. return dialogPage.route
  369. }
  370. return ''
  371. },
  372. // 自动化测试
  373. dialogPageCheckGetDialogPages() : boolean {
  374. const dialogPage = this.getDialogPage()!
  375. const dialogPages = dialogPage.getDialogPages()
  376. const res = dialogPages.length == 0
  377. return res
  378. },
  379. // 自动化测试
  380. dialogPageGetPageStyle() : UTSJSONObject {
  381. const dialogPage = this.getDialogPage()!
  382. return dialogPage.getPageStyle()
  383. },
  384. // 自动化测试
  385. dialogPageSetPageStyle() {
  386. const dialogPage = this.getDialogPage()!
  387. dialogPage.setPageStyle({
  388. backgroundColorContent: 'red'
  389. })
  390. },
  391. // 自动化测试
  392. dialogPageCheckGetElementById() : boolean {
  393. const dialogPage = this.getDialogPage()!
  394. const element = dialogPage.getElementById('dialog1-go-next-page')
  395. let res = element != null
  396. // #ifndef APP-ANDROID
  397. if (res) {
  398. const elPage = element!.getPage()
  399. console.log('elPage', elPage)
  400. res = elPage === dialogPage
  401. }
  402. // #endif
  403. return res
  404. },
  405. // 自动化测试
  406. dialogCheckGetAndroidView() : boolean {
  407. const dialogPage = this.getDialogPage()!
  408. const androidView = dialogPage.getAndroidView()
  409. const res = androidView != null
  410. return res
  411. },
  412. // 自动化测试
  413. dialogCheckGetIOSView() : boolean {
  414. const dialogPage = this.getDialogPage()!
  415. const IOSView = dialogPage.getIOSView()
  416. const res = IOSView != null
  417. return res
  418. },
  419. // 自动化测试
  420. dialogCheckGetHTMLElement() : boolean {
  421. const dialogPage = this.getDialogPage()!
  422. const HTMLView = dialogPage.getHTMLElement()
  423. const res = HTMLView != null
  424. return res
  425. },
  426. }
  427. }
  428. </script>
  429. <style>
  430. .uni-padding-wrap{
  431. padding-bottom: var(--uni-safe-area-inset-bottom);
  432. }
  433. .ml-10 {
  434. margin-left: 10px;
  435. }
  436. .choose-open-animation-type-title {
  437. font-weight: bold;
  438. }
  439. .choose-open-animation-type-radio-group {
  440. flex-direction: row;
  441. flex-wrap: wrap;
  442. margin-bottom: 20px;
  443. }
  444. .flex-row{
  445. flex-direction: row;
  446. flex-wrap: wrap;
  447. }
  448. </style>style>