advance.uvue 7.3 KB
Newer Older
Y
yurj26 已提交
1 2 3 4 5
<template>
    <view class="uni-container">
        <page-head :title="title"></page-head>

        <view class="uni-panel" v-for="(item, index) in list" :key="index">
Y
yurj26 已提交
6
            <view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="triggerCollapse(index)">
Y
yurj26 已提交
7 8 9 10 11
                <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">
Y
yurj26 已提交
12 13
                <view class="uni-navigate-item" v-for="(page,key) in item.pages" :key="key" @click="goDetailPage(page)"
                    hover-class="uni-navigate-item-active">
Y
yurj26 已提交
14 15 16 17 18 19 20
                    <text class="uni-navigate-text">{{page.name}}</text>
                    <image :src="arrowRightIcon" class="uni-icon" v-if="page.url"></image>
                </view>
            </view>
        </view>
    </view>
</template>
杜庆泉's avatar
杜庆泉 已提交
21
<script>
Y
yurj26 已提交
22 23 24 25
    import {
        doTimerTask,
        doIntervalTask,
        clearIntervalTask,
杜庆泉's avatar
杜庆泉 已提交
26
        playAssetAudio,
Y
yurj26 已提交
27
        getMetaConfig,
Y
yurj26 已提交
28 29
        quitApp,
        TimerOptions
Y
yurj26 已提交
30 31
    } from "../../uni_modules/uts-advance";

Y
yurj26 已提交
32 33 34 35 36 37 38 39 40 41 42 43
    type Page = {
        name : string,
        url ?: string
        function ?: string
    }
    type ListItem = {
        name : string,
        open : boolean,
        pages : Page[],
    }


Y
yurj26 已提交
44 45 46 47 48 49 50
    export default {
        data() {
            return {
                title: 'UTS进阶示例',
                taskId: 0,

                list: [{
Y
yurj26 已提交
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
                    name: "延迟任务",
                    open: false,
                    pages: [{
                        name: "开启延迟任务",
                        function: "testTimer"
                    }] as Page[]
                },
                {
                    name: "定时任务",
                    open: false,
                    pages: [{
                        name: "开启定时任务",
                        function: "testInterval"
                    }, {
                        name: "关闭定时任务",
                        function: "testClearInterval"
                    }] as Page[]
                },
                {
                    name: "语法示例",
                    open: false,
                    pages: [{
                        name: "进阶语法示例",
                        url: "SyntaxCase/index"
                    }, {
                        name: "参数传递示例",
                        url: "SyntaxCase/paramTest"
                    }, {
                        name: "实例测试示例",
                        url: "SyntaxCase/instanceTest"
81 82 83 84 85 86
                    },
                    {
                        name: "混编测试示例",
                        url: "SyntaxCase/MixNativeCode"
                    },
                    ] as Page[]
Y
yurj26 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
                },
                {
                    name: "日志打印",
                    open: false,
                    pages: [{
                        name: "console示例",
                        url: "SyntaxCase/consoleTest"
                    }] as Page[]
                },
                {
                    name: "平台代码示例",
                    open: false,
                    pages: [{
                        name: "UTSAndroid",
                        url: "SyntaxCase/utsAndroid"
                    }, {
                        name: "UTSiOS",
                        url: "SyntaxCase/utsiOS"
                    }] as Page[]
                },
                ] as ListItem[],
Y
yurj26 已提交
108 109 110 111 112 113
                arrowUpIcon: '/static/icons/arrow-up.png',
                arrowDownIcon: '/static/icons/arrow-down.png',
                arrowRightIcon: '/static/icons/arrow-right.png',
            }
        },
        methods: {
Y
yurj26 已提交
114
            triggerCollapse(index : number) {
Y
yurj26 已提交
115 116 117 118 119 120 121 122
                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;
                    }
                }
            },
Y
yurj26 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136
            goDetailPage(e : Page) {
                if (e.function != null) {
                    const funName = e.function
                    switch (funName) {
                        case 'testTimer':
                            this.testTimer()
                            break
                        case 'testInterval':
                            this.testInterval()
                            break
                        case 'testClearInterval':
                            this.testClearInterval()
                            break
                    }
Y
yurj26 已提交
137 138 139 140 141 142 143 144 145 146
                    return
                }
                uni.navigateTo({
                    url: `/pages/${e.url}`
                })
            },

            /**
             * 测试延迟任务
             */
Y
yurj26 已提交
147
            testTimer: function () {
Y
yurj26 已提交
148
                doTimerTask({
Y
yurj26 已提交
149
                    start: function (response) {
Y
yurj26 已提交
150 151 152 153 154
                        uni.showToast({
                            title: response,
                            icon: 'none'
                        });
                    },
Y
yurj26 已提交
155
                    work: function (response) {
Y
yurj26 已提交
156 157 158 159 160
                        uni.showToast({
                            title: response,
                            icon: 'none'
                        });
                    },
Y
yurj26 已提交
161
                } as TimerOptions);
Y
yurj26 已提交
162 163 164 165
            },
            /**
             * 测试周期任务
             */
Y
yurj26 已提交
166
            testInterval: function () {
Y
yurj26 已提交
167
                var ret = doIntervalTask({
Y
yurj26 已提交
168
                    start: function (response) {
Y
yurj26 已提交
169 170 171 172 173
                        uni.showToast({
                            title: response,
                            icon: 'none'
                        });
                    },
Y
yurj26 已提交
174
                    work: function (response) {
Y
yurj26 已提交
175 176 177 178 179
                        uni.showToast({
                            title: response,
                            icon: 'none'
                        });
                    },
Y
yurj26 已提交
180 181 182 183
                } as TimerOptions);
                if (ret.taskId != null) {
                    this.taskId = ret.taskId!;
                }
Y
yurj26 已提交
184 185 186 187
            },
            /**
             * 取消周期任务
             */
Y
yurj26 已提交
188
            testClearInterval: function () {
Y
yurj26 已提交
189 190 191
                console.log(this.taskId);
                clearIntervalTask(this.taskId);
            },
Y
yurj26 已提交
192 193 194 195 196
            // testInputDialog() {
            //     getUserInput(function (res) {
            //         console.log(res);
            //     });
            // },
Y
yurj26 已提交
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
            testQuitApp() {
                quitApp()
            },
            testMetaRead() {
                let ret = getMetaConfig();
                uni.showToast({
                    icon: "none",
                    title: '读取成功,注意查看控制台输出'
                });
                console.log(ret);
            }

        }
    }
</script>

<style>
    @import '@/common/uni-uvue.css';
杜庆泉's avatar
杜庆泉 已提交
215 216

    .uni-container {
Y
yurj26 已提交
217
        /* min-height: 100%; */
杜庆泉's avatar
杜庆泉 已提交
218
    }
Y
yurj26 已提交
219
</style>