SystemAPI.vue 4.3 KB
Newer Older
lizhongyi_'s avatar
lizhongyi_ 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<template>
    <view class="uni-container">
        <page-head :title="title"></page-head>

        <view class="uni-panel" v-for="(item, index) in list" :key="index">
            <view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="triggerCollapse(index, item)">
                <text class="uni-panel-text">{{item.name}}</text>
                <image :src="item.pages.length > 0 ? item.open ? arrowUpIcon : arrowDownIcon : arrowRightIcon"
                    class="uni-icon"></image>
            </view>
            <view class="uni-panel-c" v-if="item.open">
                <view class="uni-navigate-item" v-for="(page,key) in item.pages" :key="key" @click="goDetailPage(page)" hover-class="uni-navigate-item-active">
                    <text class="uni-navigate-text">{{page.name}}</text>
                    <image :src="arrowRightIcon" class="uni-icon" v-if="page.url"></image>
                </view>
            </view>
        </view>
    </view>
</template>·
20 21 22 23
<script>
    // #ifdef APP-ANDROID
    import { gotoDemoActivity } from "@/uni_modules/uts-nativepage";
    // #endif
lizhongyi_'s avatar
lizhongyi_ 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 87 88 89 90 91
    import { getBatteryInfo } from "@/uni_modules/uts-getbatteryinfo";

    export default {
        data() {
            return {
                title: '系统API示例',

                list: [{
                        name: "设备相关",
                        open: false,
                        pages: [{
                            name: "获取电池电量",
                            function: "testGetBatteryCapacity"
                        }]
                    },
                    {
                        name: "系统事件",
                        open: false,
                        pages: [{
                            name: "监听系统截屏",
                            url: "SystemAPI/ScreenListen/screenlisten"
                        }]
                    },
                    {
                        name: "Alert系统弹窗",
                        open: false,
                        pages: [{
                            name: "Alert弹窗",
                            url: "SystemAPI/Alert/alert"
                        }]
                    },
                    {
                        name: "android平台",
                        open: false,
                        pages: [{
                            name: "自定义activity(需自定义基座)",
                            function: "testGotoDemoActivity"
                        }]
                    }
                ],
                arrowUpIcon: '/static/icons/arrow-up.png',
                arrowDownIcon: '/static/icons/arrow-down.png',
                arrowRightIcon: '/static/icons/arrow-right.png',
            }
        },
        methods: {
            triggerCollapse(index) {
                for (var i = 0; i < this.list.length; ++i) {
                    if (index == i) {
                        this.list[i].open = !this.list[i].open;
                    } else {
                        this.list[i].open = false;
                    }
                }
            },
            goDetailPage(e) {
                if (e.function) {
                    this[e.function]()
                    return
                }
                uni.navigateTo({
                    url: `/pages/${e.url}`
                })
            },

            testGetBatteryCapacity() {
                getBatteryInfo({
                    success(res) {
杜庆泉's avatar
杜庆泉 已提交
92
						console.log(res)
lizhongyi_'s avatar
lizhongyi_ 已提交
93 94 95 96 97 98 99
                        uni.showToast({
                            title: "当前电量:" + res.level + '%',
                            icon: 'none'
                        });
                    }
                })
            },
100 101
            testGotoDemoActivity() {
                // #ifdef APP-ANDROID
lizhongyi_'s avatar
lizhongyi_ 已提交
102 103 104 105 106 107
                let ret = gotoDemoActivity();
                if (!ret) {
                    uni.showToast({
                        icon: 'none',
                        title: '需要在自定义基座中运行'
                    })
108 109
                }
                // #endif
lizhongyi_'s avatar
lizhongyi_ 已提交
110 111 112 113 114 115 116 117 118 119 120 121
            }
        }
    }
</script>

<style>
    @import '@/common/uni-uvue.css';
    
    .uni-container {
        min-height: 100%;
    }
</style>