dialog-page.uvue 6.5 KB
Newer Older
1
<template>
2
  <view class="uni-padding-wrap">
3 4 5 6
    <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>
7 8
    <button class="uni-common-mt" id="go-next-page-open-dialog1" @click="goNextPageOpenDialog1">go next page & open
      dialog1</button>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  </view>
</template>

<script lang='uts'>
  import {
    state,
    setLifeCycleNum
  } from '@/store/index.uts'

  export default {
    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() {
43
        const dialogPage = uni.openDialogPage({
DCloud-WZF's avatar
DCloud-WZF 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
            url: '/pages/API/dialog-page/dialog-1?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)
            }
          }) !
          const fn1 = (options: any | null) => {
            console.log('dialogPage1 be triggered fn1', options)
62 63
            setLifeCycleNum(state.lifeCycleNum + 1)
          }
DCloud-WZF's avatar
DCloud-WZF 已提交
64 65 66 67 68 69 70 71 72 73 74
        const fn11 = (options: any | null) => {
          console.log('dialogPage1 be triggered fn11', options)
          setLifeCycleNum(state.lifeCycleNum + 1)
        }
        const fn2 = (options: any | null) => {
          console.log('dialogPage1 be triggered fn2', options)
          setLifeCycleNum(state.lifeCycleNum + 1)
        }
        const fnOnce = (options: any | null) => {
          console.log('dialogPage1 be triggered fnOnce', options)
          setLifeCycleNum(state.lifeCycleNum + 1)
75
        }
76
        dialogPage.on('fn1', fn1)
77 78 79
        dialogPage.on('fn1', fn11)
        dialogPage.on('fn2', fn2)
        dialogPage.once('fnOnce', fnOnce)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
      },
      openDialog2() {
        uni.openDialogPage({
          url: '/pages/API/dialog-page/dialog-2',
          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)
          }
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
        })
      },
      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',
                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)
          }
        })
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
      },
      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)
          }
        })
      },
      closeSpecifiedDialog(index: number) {
168
        const dialogPages = this.$page.getDialogPages()
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
        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)
          }
        })
187 188 189 190 191 192 193 194 195
      },
      setLifeCycleNum(value: number) {
        setLifeCycleNum(value)
      },
      getLifeCycleNum(): number {
        return state.lifeCycleNum
      }
    }
  }
196
</script>