123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- <template>
- <!-- #ifdef APP -->
- <scroll-view class="page-scroll-view">
- <!-- #endif -->
- <view>
- <page-head title="getCurrentPages"></page-head>
- <view class="uni-padding-wrap">
- <button @click="_getCurrentPages">getCurrentPages</button>
- <view v-if="pages.length" style="padding: 15px 0px">
- <text>当前页面栈中 {{ pages.length }} 个页面,列表如下:</text>
- <template v-for="(page, index) in pages" :key="page.route">
- <text style="margin-top: 5px">index: {{ index }}, route: {{ page.route }}</text>
- </template>
- </view>
- <!-- #ifndef MP -->
- <button class="uni-common-mt" @click="check$page">check $page</button>
- <button class="uni-common-mt" @click="checkGetParentPage">
- check getParentPage
- </button>
- <button class="uni-common-mt" @click="checkGetDialogPages">
- check getDialogPages
- </button>
- <button id="check-get-element-by-id-btn" class="uni-common-mt" @click="checkGetElementById">
- check getElementById
- </button>
- <button class="uni-common-mt" @click="checkGetAndroidView">
- check getAndroidView
- </button>
- <button class="uni-common-mt" @click="checkGetIOSView">
- check getIOSView
- </button>
- <button class="uni-common-mt" @click="checkGetHTMLElement">
- check getHTMLElement
- </button>
- <!-- #endif -->
- <!-- #ifdef APP-ANDROID -->
- <button class="uni-common-mt" @click="checkGetAndroidActivity">
- check getAndroidActivity
- </button>
- <!-- #endif -->
- </view>
- <!-- #ifndef MP -->
- <page-head title="currentPageStyle"></page-head>
- <template v-for="(item, index) in PageStyleArray">
- <view class="page-style-item" v-if="currentPageStyle[item.key] != null" :key="index">
- <view class="item-text">
- <text class="item-text-key">{{ item.key }}:</text>
- <text class="item-text-value">{{
- currentPageStyle[item.key]
- }}</text>
- </view>
- <view class="set-value" v-if="item.type == 'boolean'">
- <switch :checked="currentPageStyle.getBoolean(item.key)"
- @change="switchChange(item.key, $event as UniSwitchChangeEvent)">
- </switch>
- </view>
- <view class="set-value" v-else-if="item.type == 'number'">
- <slider :value="currentPageStyle.getNumber(item.key)" :show-value="true"
- @change="sliderChange(item.key, $event as UniSliderChangeEvent)" />
- </view>
- <view class="set-value" v-else-if="item.type == 'string'">
- <radio-group class="radio-set-value" @change="radioChange(item.key, $event as RadioGroupChangeEvent)">
- <radio class="radio-value" v-for="(item2, index2) in item.value" :key="index2" :value="item2">{{ item2 }}
- </radio>
- </radio-group>
- </view>
- </view>
- </template>
- <!-- #ifndef APP-HARMONY -->
- <button style="margin: 10px" @click="goSetDisablePullDownRefresh">
- go set disable pullDownRefresh
- </button>
- <!-- #endif -->
- <!-- #endif -->
- </view>
- <!-- #ifdef APP -->
- </scroll-view>
- <!-- #endif -->
- </template>
- <script>
- import { PageStyleItem, PageStyleArray } from './page-style.uts';
- class Page {
- constructor(public route : string) {
- }
- }
- export default {
- data() {
- return {
- checked: false,
- pages: [] as Page[],
- PageStyleArray: PageStyleArray as PageStyleItem[],
- currentPageStyle: {} as UTSJSONObject,
- testing: false
- }
- },
- computed: {
- pageStyleText() : string {
- return JSON.stringify(this.currentPageStyle)
- }
- },
- // #ifndef MP
- onLoad() {
- this.getPageStyle();
- },
- // #endif
- onReady() {
- // #ifdef APP-ANDROID
- this.setPageStyle({
- 'androidThreeButtonNavigationBackgroundColor': 'transparent',
- 'androidThreeButtonNavigationStyle': 'black'
- });
- this.getPageStyle();
- // #endif
- },
- onPullDownRefresh() {
- setTimeout(() => {
- uni.stopPullDownRefresh()
- }, 2000)
- },
- methods: {
- startPullDownRefresh() {
- uni.startPullDownRefresh()
- },
- _getCurrentPages: function () {
- this.pages.length = 0
- const pages = getCurrentPages()
- this.pages.push(new Page(pages[0].route))
- if (this.pages[0].route.includes('/tabBar/') || this.pages[0].route == '/') {
- this.checked = true
- }
- for (let i = 1; i < pages.length; i++) {
- this.pages.push(new Page(pages[i].route))
- if (pages[i].route.includes('/tabBar/')) {
- this.checked = false
- }
- }
- },
- /// get-set-page-style
- radioChange(key : string, e : RadioGroupChangeEvent) {
- this.setStyleValue(key, e.detail.value);
- },
- sliderChange(key : string, e : UniSliderChangeEvent) {
- this.setStyleValue(key, e.detail.value);
- },
- switchChange(key : string, e : UniSwitchChangeEvent) {
- this.setStyleValue(key, e.detail.value);
- },
- setStyleValue(key : string, value : any) {
- const style = {}
- style[key] = value
- this.setPageStyle(style)
- this.getPageStyle()
- },
- getPageStyle() : UTSJSONObject {
- const pages = getCurrentPages();
- const currentPage = pages[pages.length - 1];
- this.currentPageStyle = currentPage.getPageStyle()
- console.log(this.currentPageStyle)
- return this.currentPageStyle;
- },
- setPageStyle(style : UTSJSONObject) {
- console.log('setPageStyle:', style);
- const pages = getCurrentPages();
- const currentPage = pages[pages.length - 1];
- currentPage.setPageStyle(style);
- },
- goSetDisablePullDownRefresh() {
- uni.navigateTo({
- url: '/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh'
- });
- },
- getCurrentPage() : UniPage {
- const pages = getCurrentPages()
- return pages[pages.length - 1]
- },
- check$page() : boolean {
- const page = this.getCurrentPage()
- let res = this.$page === page
- if (this.testing && res) {
- res = page.options['test'] == '123'
- if (res) {
- res = page.route == 'pages/API/get-current-pages/get-current-pages'
- }
- }
- console.log('check $page', res)
- uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' })
- return res
- },
- checkGetParentPage() : boolean {
- const page = this.getCurrentPage()
- const parentPage = page.getParentPage()
- const res = parentPage == null
- console.log('check getParentPage', res)
- uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' })
- return res
- },
- checkGetDialogPages() : boolean {
- const page = this.getCurrentPage()
- const dialogPages = page.getDialogPages()
- const res = Array.isArray(dialogPages) && dialogPages.length == 0
- uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' })
- console.log('check getDialogPages', res)
- return res
- },
- checkGetElementById() : boolean {
- const page = this.getCurrentPage()
- const element = page.getElementById('check-get-element-by-id-btn')
- 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
- },
- checkGetAndroidView() : boolean {
- const page = this.getCurrentPage()
- const androidView = page.getAndroidView()
- const res = androidView != null
- console.log('check getAndroidView', res)
- uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' })
- return res
- },
- checkGetIOSView() : boolean {
- const page = this.getCurrentPage()
- const IOSView = page.getIOSView()
- const res = IOSView != null
- console.log('check getIOSView', res)
- uni.showToast(res ? { title: 'check success' } : { title: '仅 IOS uts 插件环境支持', icon: 'error' })
- return res
- },
- checkGetHTMLElement() : boolean {
- const page = this.getCurrentPage()
- const HTMLView = page.getHTMLElement()
- const res = HTMLView != null
- console.log('check getHTMLElement', res)
- uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' })
- return res
- },
- checkGetAndroidActivity() : boolean {
- const page = this.getCurrentPage()
- const activity = page.getAndroidActivity()
- const res = activity != null
- console.log('check getAndroidActivity', res)
- uni.showToast(res ? { title: 'check success' } : { title: 'check getAndroidActivity', icon: 'error' })
- return res
- }
- },
- }
- </script>
- <style>
- .page {
- flex: 1;
- padding: 10px;
- }
- .page-style {
- margin-top: 15px;
- }
- .page-style-item {
- padding: 10px;
- margin-top: 10px;
- background-color: #ffffff;
- border-radius: 5px;
- }
- .item-text {
- flex-direction: row;
- }
- .item-text-key {
- font-weight: bold;
- }
- .item-text-value {
- margin-left: 5px;
- }
- .set-value {
- margin-top: 10px;
- }
- .radio-set-value {
- flex-direction: row;
- }
- .radio-value {
- margin-left: 10px;
- }
- </style>
|