dialog-page.uvue 10.4 KB
Newer Older
1
<template>
2
  <view class="uni-padding-wrap">
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
    <button class="uni-common-mt" id="go-next-page" @click="goNextPage">
      go next page
    </button>
    <button class="uni-common-mt" id="open-dialog1" @click="openDialog1">
      open dialog 1
    </button>
    <button class="uni-common-mt" id="open-dialog1-wrong-path" @click="openDialog1WrongPath">
      open dialog page 1 with wrong path
    </button>
    <button class="uni-common-mt" id="go-next-page-open-dialog1" @click="goNextPageOpenDialog1">
      go next page & open dialog1
    </button>
    <button class="uni-common-mt" id="open-dialog1" @click="openDialog3">
      open dialog 3 test page style
    </button>
    <text class="uni-common-mt choose-open-animation-type-title">choose open dialogPage animationType</text>
    <radio-group class="choose-open-animation-type-radio-group" @change="handleOpenAnimationType">
      <radio class="ml-10 uni-common-mt" v-for="item in openAnimationTypeList" :key="item" :value="item"
        :checked="openAnimationType == item">{{ item }}
      </radio>
    </radio-group>
24 25 26
  </view>
</template>

27
<script lang="uts">
28 29 30 31 32
  import {
    state,
    setLifeCycleNum
  } from '@/store/index.uts'

33 34 35 36 37 38 39 40 41 42 43
  type OpenAnimationType =
    'auto' |
    'none' |
    'slide-in-right' |
    'slide-in-left' |
    'slide-in-top' |
    'slide-in-bottom' |
    'fade-in' |
    'zoom-out' |
    'zoom-fade-out'

44 45 46 47
  export default {
    data() {
      return {
        jest_click_x: -1,
48 49 50 51 52 53 54 55 56 57 58 59 60
        jest_click_y: -1,
        openAnimationType: 'none' as OpenAnimationType,
        openAnimationTypeList: [
          'auto',
          'none',
          'slide-in-right',
          'slide-in-left',
          'slide-in-top',
          'slide-in-bottom',
          'fade-in',
          'zoom-out',
          'zoom-fade-out'
        ]
61
      }
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
62
    },
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    onLoad() {
      console.log('dialogPage parent onLoad')
    },
    onShow() {
      console.log('dialogPage parent onShow')
      setLifeCycleNum(state.lifeCycleNum + 10)
    },
    onReady() {
      console.log('dialogPage parent onReady')
    },
    onHide() {
      console.log('dialogPage parent onHide')
      setLifeCycleNum(state.lifeCycleNum - 10)
    },
    onUnload() {
      console.log('dialogPage parent onUnload')
    },
    methods: {
      goNextPage() {
        uni.navigateTo({
          url: '/pages/API/dialog-page/next-page'
        })
      },
      openDialog1() {
87 88
        uni.openDialogPage({
          url: '/pages/API/dialog-page/dialog-1?name=dialog1',
89
          animationType: this.openAnimationType,
90 91 92 93 94 95 96 97 98 99 100 101
          success(res) {
            console.log('openDialogPage1 success', res)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum + 1)
          },
          fail(err) {
            console.log('openDialogPage1 fail', err)
            setLifeCycleNum(state.lifeCycleNum - 4)
          },
          complete(res) {
            console.log('openDialogPage1 complete', res)
            // 自动化测试
102 103
            setLifeCycleNum(state.lifeCycleNum + 1)
          }
104
        })
105 106 107 108
      },
      openDialog2() {
        uni.openDialogPage({
          url: '/pages/API/dialog-page/dialog-2',
109
          animationType: this.openAnimationType,
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
          disableEscBack: true,
          success(res) {
            console.log('openDialog2 success', res)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum + 1)
          },
          fail(err) {
            console.log('openDialog2 fail', err)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum - 4)
          },
          complete(res) {
            console.log('openDialog2 complete', res)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum + 1)
          }
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
        })
      },
      openDialog1WrongPath() {
        uni.openDialogPage({
          url: '/pages/API/dialog-page/dialog-11?name=dialog1',
          success(res) {
            console.log('openDialogPage1 success', res)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum + 1)
          },
          fail(err) {
            console.log('openDialogPage1 fail', err)
            setLifeCycleNum(state.lifeCycleNum - 4)
          },
          complete(res) {
            console.log('openDialogPage1 complete', res)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum + 1)
          }
        })
      },
      goNextPageOpenDialog1() {
        uni.navigateTo({
          url: '/pages/API/dialog-page/next-page',
          success() {
            setTimeout(() => {
              uni.openDialogPage({
                url: '/pages/API/dialog-page/dialog-1?name=dialog1',
154
                animationType: this.openAnimationType,
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
                success(res) {
                  console.log('openDialogPage1 success', res)
                  // 自动化测试
                  setLifeCycleNum(state.lifeCycleNum + 1)
                },
                fail(err) {
                  console.log('openDialogPage1 fail', err)
                  // 自动化测试
                  setLifeCycleNum(state.lifeCycleNum - 4)
                },
                complete(res) {
                  console.log('openDialogPage1 complete', res)
                  // 自动化测试
                  setLifeCycleNum(state.lifeCycleNum + 1)
                }
              })
            }, 1000)
          }
        })
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
      },
      closeDialog() {
        uni.closeDialogPage({
          success(res) {
            console.log('closeDialog success', res)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum + 1)
          },
          fail(err) {
            console.log('closeDialog fail', err)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum - 4)
          },
          complete(res) {
            console.log('closeDialog complete', res)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum + 1)
          }
        })
      },
194
      closeSpecifiedDialog(index : number) {
195
        const dialogPages = this.$page.getDialogPages()
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
        uni.closeDialogPage({
          dialogPage: dialogPages[index],
          success(res) {
            console.log('closeSomeOneDialog success', res)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum + 1)
          },
          fail(err) {
            console.log('closeSomeOneDialog fail', err)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum - 4)
          },
          complete(res) {
            console.log('closeSomeOneDialog complete', res)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum + 1)
          }
        })
214
      },
215
      setLifeCycleNum(value : number) {
216 217
        setLifeCycleNum(value)
      },
218
      getLifeCycleNum() : number {
219
        return state.lifeCycleNum
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
      },
      jest_OpenDialog1() {
        uni.openDialogPage({
          url: '/pages/API/dialog-page/dialog-1?name=dialog1'
        })
      },
      jest_CloseDialog1() {
        uni.closeDialogPage({})
      },
      jest_getTapPoint() {
        const systemInfo = uni.getSystemInfoSync()
        let ratio = 1
        if (systemInfo.platform == 'android') {
          ratio = systemInfo.devicePixelRatio
        }
        this.jest_click_x = systemInfo.screenWidth / 2 * ratio
        this.jest_click_y = systemInfo.statusBarHeight * ratio + 10
      },
      openDialog2ForTest() {
        uni.openDialogPage({
          url: '/pages/API/dialog-page/dialog-2'
        });
      },
      closeDialog2ForTest() {
        uni.closeDialogPage({});
      },
246
      setPageStyleForTest(style : UTSJSONObject) {
247 248 249
        const pages = this.$page.getDialogPages();
        if (pages.length > 0) pages[pages.length - 1].setPageStyle(style);
      },
250 251 252 253 254 255
      openDialog3() {
        uni.openDialogPage({ url: '/pages/API/dialog-page/dialog-3', animationType: this.openAnimationType })
      },
      handleOpenAnimationType(e : RadioGroupChangeEvent) {
        this.openAnimationType = e.detail.value as OpenAnimationType
      },
256
      // 自动化测试
257
      getDialogPage() : UniPage | null {
258 259 260
        const dialogPages = this.$page.getDialogPages()
        return dialogPages.length > 0 ? dialogPages[0] : null
      },
261
      // 自动化测试
262 263
      dialogPageCheckGetDialogPages() : boolean {
        const dialogPage = this.getDialogPage()!
264 265 266 267
        const dialogPages = dialogPage.getDialogPages()
        const res = dialogPages.length == 0
        return res
      },
268
      // 自动化测试
269 270
      dialogPageGetPageStyle() : UTSJSONObject {
        const dialogPage = this.getDialogPage()!
271 272
        return dialogPage.getPageStyle()
      },
273
      // 自动化测试
274
      dialogPageSetPageStyle() {
275
        const dialogPage = this.getDialogPage()!
276 277 278 279
        dialogPage.setPageStyle({
          backgroundColorContent: 'red'
        })
      },
280
      // 自动化测试
281 282
      dialogPageCheckGetElementById() : boolean {
        const dialogPage = this.getDialogPage()!
283 284 285 286 287 288 289 290 291 292 293
        const element = dialogPage.getElementById('dialog1-go-next-page')
        let res = element != null
        // #ifndef APP-ANDROID
        if (res) {
          const elPage = element!.getPage()
          console.log('elPage', elPage)
          res = elPage === dialogPage
        }
        // #endif
        return res
      },
294
      // 自动化测试
295 296
      dialogCheckGetAndroidView() : boolean {
        const dialogPage = this.getDialogPage()!
297 298 299 300
        const androidView = dialogPage.getAndroidView()
        const res = androidView != null
        return res
      },
301
      // 自动化测试
302 303
      dialogCheckGetIOSView() : boolean {
        const dialogPage = this.getDialogPage()!
304 305 306 307
        const IOSView = dialogPage.getIOSView()
        const res = IOSView != null
        return res
      },
308
      // 自动化测试
309 310
      dialogCheckGetHTMLElement() : boolean {
        const dialogPage = this.getDialogPage()!
311 312 313 314
        const HTMLView = dialogPage.getHTMLElement()
        const res = HTMLView != null
        return res
      },
315 316
    }
  }
317
</script>
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332

<style>
  .ml-10 {
    margin-left: 10px;
  }

  .choose-open-animation-type-title {
    font-weight: bold;
  }

  .choose-open-animation-type-radio-group {
    flex-direction: row;
    flex-wrap: wrap;
  }
</style>