dialog-1.uvue 6.6 KB
Newer Older
1 2 3
<template>
  <view id="dialog1" class="dialog-container">
    <view class="dialog-content">
4
      <text>title: {{ title }}</text>
5
      <text class="mt-10">onBackPress return true</text>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
      <button class="mt-10" id="dialog1-go-next-page" @click="goNextPage">
        go next page
      </button>
      <button class="mt-10" id="dialog1-open-dialog2" @click="openDialog2">
        openDialog2
      </button>
      <button class="mt-10" id="dialog1-close-dialog" @click="closeDialog">
        closeDialog
      </button>
      <button class="mt-10" id="dialog1-close-this-dialog" @click="closeThisDialog">
        closeThisDialog
      </button>
      <button class="mt-10" @click="checkGetParentPage">
        check getParentPage
      </button>
      <button class="mt-10" @click="checkGetElementById">
        check getElementById
      </button>
      <button class="mt-10" @click="toggleBackgroundColor">
        toggleBackgroundColor
      </button>
27
      <button class="mt-10" id="dialog1-back" @click="back">back</button>
28 29
      <input class="uni-common-mt" style="border-width: 1px; border-style: solid" :focus="true"
        value="DialogPage中焦点测试" />
30 31 32 33 34 35 36 37 38 39 40 41 42 43
    </view>
  </view>
</template>

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

  export default {
    data() {
      return {
        title: 'dialog 1',
44
        backgroundColorContent: 'transparent'
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
      }
    },
    onLoad(options : OnLoadOptions) {
      console.log('dialog 1 onLoad', options)
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum + 1)
      if (options['name'] == 'dialog1') {
        // 自动化测试
        setLifeCycleNum(state.lifeCycleNum + 1)
      }
    },
    onShow() {
      console.log('dialog 1 onShow')
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum + 1)
    },
    onReady() {
      console.log('dialog 1 onReady')
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum + 1)
      const currentPages = getCurrentPages()
66
      const parentPage = this.$page.getParentPage()!
67 68
      const grandParentPage = parentPage.getParentPage()
      const dialogPages = parentPage.getDialogPages()
69
      const dialogPage = this.$page
70 71 72 73 74 75 76
      if (
        currentPages.length == 1 &&
        grandParentPage == null &&
        dialogPages.indexOf(dialogPage) != -1
      ) {
        // 自动化测试
        setLifeCycleNum(state.lifeCycleNum + 1)
DCloud-WZF's avatar
DCloud-WZF 已提交
77
      }
78 79 80 81 82 83 84 85 86 87 88 89
    },
    onHide() {
      console.log('dialog 1 onHide')
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum - 1)
    },
    onUnload() {
      console.log('dialog 1 onUnload')
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum - 5)
    },
    onBackPress(options : OnBackPressOptions) : boolean | null {
90
      console.log('dialogPage1 onBackPress', options)
91 92 93 94 95 96 97 98 99 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
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum + 1)
      return true
    },
    methods: {
      goNextPage() {
        uni.navigateTo({ url: '/pages/API/dialog-page/next-page' })
      },
      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)
          }
        })
      },
      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)
          }
        })
      },
      closeThisDialog() {
        uni.closeDialogPage({
141
          dialogPage: this.$page,
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
          success(res) {
            console.log('closeThisDialog success', res)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum + 1)
          },
          fail(err) {
            console.log('closeThisDialog fail', err)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum - 4)
          },
          complete(res) {
            console.log('closeThisDialog complete', res)
            // 自动化测试
            setLifeCycleNum(state.lifeCycleNum + 1)
          }
        })
      },
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
      checkGetParentPage() : boolean {
        const parentPage = this.$page.getParentPage()
        console.log('checkGetParentPage', parentPage)
        const res = parentPage != null
        uni.showToast(res ? {
          title: 'check success'
        } : {
          title: 'check fail',
          icon: 'error'
        })
        return res
      },
      checkGetElementById() : boolean {
        const page = this.$page
        const element = page.getElementById('dialog1-go-next-page')
        let res = element != null
        // #ifndef APP-ANDROID
        if (res) {
          const elPage = element!.getPage()
          console.log('elPage', elPage)
          res = elPage === page
        }
        // #endif
        console.log('check getElementById', res)
        uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' })
        return res
      },
      toggleBackgroundColor() {
        this.backgroundColorContent = this.backgroundColorContent == 'transparent' ? 'rgb(0, 122, 255)' : 'transparent'
        this.$page.setPageStyle({
          backgroundColorContent: this.backgroundColorContent
        })
      },
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
      back() {
        uni.navigateBack()
      }
    }
  }
</script>

<style>
  .dialog-container {
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .dialog-content {
    width: 80%;
    padding: 10px;
    background-color: #fff;
    border-radius: 6px;
  }

  .mt-10 {
    margin-top: 10px;
  }
219
</style>