dialog-1.uvue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view id="dialog1" class="dialog-container">
  3. <view class="dialog-content">
  4. <text>title: {{ title }}</text>
  5. <text class="mt-10">onBackPress return true</text>
  6. <button class="mt-10" id="dialog1-go-next-page" @click="goNextPage">
  7. go next page
  8. </button>
  9. <button class="mt-10" id="dialog1-open-dialog2" @click="openDialog2">
  10. openDialog2
  11. </button>
  12. <button class="mt-10" id="dialog1-close-dialog" @click="closeDialog">
  13. closeDialog
  14. </button>
  15. <button class="mt-10" id="dialog1-close-this-dialog" @click="closeThisDialog">
  16. closeThisDialog
  17. </button>
  18. <button class="mt-10" @click="checkGetParentPage">
  19. check getParentPage
  20. </button>
  21. <button class="mt-10" @click="checkGetElementById">
  22. check getElementById
  23. </button>
  24. <button class="mt-10" @click="toggleBackgroundColor">
  25. toggleBackgroundColor
  26. </button>
  27. <button class="mt-10" id="dialog1-back" @click="back">back</button>
  28. <input class="uni-common-mt" style="border-width: 1px; border-style: solid" :focus="true"
  29. value="DialogPage中焦点测试" />
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import {
  35. state,
  36. setLifeCycleNum
  37. } from '@/store/index.uts'
  38. export default {
  39. data() {
  40. return {
  41. title: 'dialog 1',
  42. backgroundColorContent: 'transparent'
  43. }
  44. },
  45. onLoad(options : OnLoadOptions) {
  46. console.log('dialog 1 onLoad', options)
  47. // 自动化测试
  48. setLifeCycleNum(state.lifeCycleNum + 1)
  49. if (options['name'] == 'dialog1') {
  50. // 自动化测试
  51. setLifeCycleNum(state.lifeCycleNum + 1)
  52. }
  53. },
  54. onShow() {
  55. console.log('dialog 1 onShow')
  56. // 自动化测试
  57. setLifeCycleNum(state.lifeCycleNum + 1)
  58. },
  59. onReady() {
  60. console.log('dialog 1 onReady')
  61. // 自动化测试
  62. setLifeCycleNum(state.lifeCycleNum + 1)
  63. const currentPages = getCurrentPages()
  64. const parentPage = this.$page.getParentPage()!
  65. const grandParentPage = parentPage.getParentPage()
  66. const dialogPages = parentPage.getDialogPages()
  67. const dialogPage = this.$page
  68. if (
  69. currentPages.length == 1 &&
  70. grandParentPage == null &&
  71. dialogPages.indexOf(dialogPage) != -1
  72. ) {
  73. // 自动化测试
  74. setLifeCycleNum(state.lifeCycleNum + 1)
  75. }
  76. },
  77. onHide() {
  78. console.log('dialog 1 onHide')
  79. // 自动化测试
  80. setLifeCycleNum(state.lifeCycleNum - 1)
  81. },
  82. onUnload() {
  83. console.log('dialog 1 onUnload')
  84. // 自动化测试
  85. setLifeCycleNum(state.lifeCycleNum - 5)
  86. },
  87. onBackPress(options : OnBackPressOptions) : boolean | null {
  88. console.log('dialogPage1 onBackPress', options)
  89. // 自动化测试
  90. setLifeCycleNum(state.lifeCycleNum + 1)
  91. return true
  92. },
  93. methods: {
  94. goNextPage() {
  95. uni.navigateTo({ url: '/pages/API/dialog-page/next-page' })
  96. },
  97. openDialog2() {
  98. uni.openDialogPage({
  99. url: '/pages/API/dialog-page/dialog-2',
  100. disableEscBack: true,
  101. success(res) {
  102. console.log('openDialog2 success', res)
  103. // 自动化测试
  104. setLifeCycleNum(state.lifeCycleNum + 1)
  105. },
  106. fail(err) {
  107. console.log('openDialog2 fail', err)
  108. // 自动化测试
  109. setLifeCycleNum(state.lifeCycleNum - 4)
  110. },
  111. complete(res) {
  112. console.log('openDialog2 complete', res)
  113. // 自动化测试
  114. setLifeCycleNum(state.lifeCycleNum + 1)
  115. }
  116. })
  117. },
  118. closeDialog() {
  119. uni.closeDialogPage({
  120. success(res) {
  121. console.log('closeDialog success', res)
  122. // 自动化测试
  123. setLifeCycleNum(state.lifeCycleNum + 1)
  124. },
  125. fail(err) {
  126. console.log('closeDialog fail', err)
  127. // 自动化测试
  128. setLifeCycleNum(state.lifeCycleNum - 4)
  129. },
  130. complete(res) {
  131. console.log('closeDialog complete', res)
  132. // 自动化测试
  133. setLifeCycleNum(state.lifeCycleNum + 1)
  134. }
  135. })
  136. },
  137. closeThisDialog() {
  138. uni.closeDialogPage({
  139. dialogPage: this.$page,
  140. success(res) {
  141. console.log('closeThisDialog success', res)
  142. // 自动化测试
  143. setLifeCycleNum(state.lifeCycleNum + 1)
  144. },
  145. fail(err) {
  146. console.log('closeThisDialog fail', err)
  147. // 自动化测试
  148. setLifeCycleNum(state.lifeCycleNum - 4)
  149. },
  150. complete(res) {
  151. console.log('closeThisDialog complete', res)
  152. // 自动化测试
  153. setLifeCycleNum(state.lifeCycleNum + 1)
  154. }
  155. })
  156. },
  157. checkGetParentPage() : boolean {
  158. const parentPage = this.$page.getParentPage()
  159. console.log('checkGetParentPage', parentPage)
  160. const res = parentPage != null
  161. uni.showToast(res ? {
  162. title: 'check success'
  163. } : {
  164. title: 'check fail',
  165. icon: 'error'
  166. })
  167. return res
  168. },
  169. checkGetElementById() : boolean {
  170. const page = this.$page
  171. const element = page.getElementById('dialog1-go-next-page')
  172. let res = element != null
  173. // #ifndef APP-ANDROID
  174. if (res) {
  175. const elPage = element!.getPage()
  176. console.log('elPage', elPage)
  177. res = elPage === page
  178. }
  179. // #endif
  180. console.log('check getElementById', res)
  181. uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' })
  182. return res
  183. },
  184. toggleBackgroundColor() {
  185. this.backgroundColorContent = this.backgroundColorContent == 'transparent' ? 'rgb(0, 122, 255)' : 'transparent'
  186. this.$page.setPageStyle({
  187. backgroundColorContent: this.backgroundColorContent
  188. })
  189. },
  190. back() {
  191. uni.navigateBack()
  192. }
  193. }
  194. }
  195. </script>
  196. <style>
  197. .dialog-container {
  198. width: 100%;
  199. height: 100%;
  200. background-color: rgba(0, 0, 0, 0.3);
  201. display: flex;
  202. justify-content: center;
  203. align-items: center;
  204. }
  205. .dialog-content {
  206. width: 80%;
  207. padding: 10px;
  208. background-color: #fff;
  209. border-radius: 6px;
  210. }
  211. .mt-10 {
  212. margin-top: 10px;
  213. }
  214. </style>