advance.vue 7.6 KB
Newer Older
杜庆泉's avatar
init  
杜庆泉 已提交
1
<template>
Y
yurj26 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
    <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>
杜庆泉's avatar
init  
杜庆泉 已提交
19
</template>
杜庆泉's avatar
杜庆泉 已提交
20
<script>
Y
yurj26 已提交
21 22 23 24 25 26
    import {
        doTimerTask,
        doIntervalTask,
        clearIntervalTask,
        playAssetAudio,
        getMetaConfig,
杜庆泉's avatar
杜庆泉 已提交
27 28
        quitApp,
		arrayConvert
Y
yurj26 已提交
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
    } from "../../uni_modules/uts-advance";

    export default {
        data() {
            return {
                title: 'UTS进阶示例',
                taskId: 0,

                list: [{
                        name: "延迟任务",
                        open: false,
                        pages: [{
                            name: "开启延迟任务",
                            function: "testTimer"
                        }]
                    },
                    {
                        name: "定时任务",
                        open: false,
                        pages: [{
                            name: "开启定时任务",
                            function: "testInterval"
                        }, {
                            name: "关闭定时任务",
                            function: "testClearInterval"
                        }]
                    },
lizhongyi_'s avatar
lizhongyi_ 已提交
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 92
					{
					    name: "资源加载示例",
					    open: false,
					    pages: [{
					        name: "图片加载示例",
					        url: "resource/resource"
					    },{
					        name: "文件读取示例",
					        url: "resource/fileRead"
					    }]
					},
					{
					    name: "组件开发示例",
					    open: false,
					    pages: [{
					        name: "Hello UTS Component",
					        url: "component/helloView"
					    }]
					},
					{
					    name: "android平台示例",
					    open: false,
					    pages: [{
					        name: "activity生命周期监听",
					        url: "lifecycle/lifecycle"
					    }, {
					        name: "播放asset音频(需自定义基座)",
					        url: "advance/android/assetaudio"
					    }, {
					        name: "操作DecorView",
					        url: "advance/android/decorview"
					    }, {
					        name: "读取meta配置",
					        function: "testMetaRead"
					    }, {
					        name: "退出当前应用",
					        function: "testQuitApp"
杜庆泉's avatar
杜庆泉 已提交
93 94 95
					    },{
					        name: "数组转换测试",
					        function: "testArrayConvert"
lizhongyi_'s avatar
lizhongyi_ 已提交
96 97 98 99 100 101 102 103 104 105
					    }]
					},
					{
					    name: "iOS平台示例",
					    open: false,
					    pages: [{
					        name: "资源路径获取示例",
					        url: "advance/iOS/getResourcePath"
					    }]
					},
Y
yurj26 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119
                    {
                        name: "语法示例",
                        open: false,
                        pages: [{
                            name: "进阶语法示例",
                            url: "SyntaxCase/index"
                        }, {
                            name: "参数传递示例",
                            url: "SyntaxCase/paramTest"
                        },{
                            name: "实例测试示例",
                            url: "SyntaxCase/instanceTest"
                        }]
                    },
lizhongyi_'s avatar
lizhongyi_ 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
					{
					    name: "日志打印",
					    open: false,
					    pages: [{
					        name: "console示例",
					        url: "SyntaxCase/consoleTest"
					    }]
					},
                    {
                        name: "平台代码示例",
                        open: false,
                        pages: [{
                            name: "UTSAndroid",
                            url: "SyntaxCase/utsAndroid"
                        }, {
                            name: "UTSiOS",
                            url: "SyntaxCase/utsiOS"
                        }]
                    },
Y
yurj26 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 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 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
                ],
                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}`
                })
            },

            /**
             * 测试延迟任务
             */
            testTimer: function() {
                doTimerTask({
                    start: function(response) {
                        uni.showToast({
                            title: response,
                            icon: 'none'
                        });
                    },
                    work: function(response) {
                        uni.showToast({
                            title: response,
                            icon: 'none'
                        });
                    },
                });
            },
            /**
             * 测试周期任务
             */
            testInterval: function() {
                var ret = doIntervalTask({
                    start: function(response) {
                        uni.showToast({
                            title: response,
                            icon: 'none'
                        });
                    },
                    work: function(response) {
                        uni.showToast({
                            title: response,
                            icon: 'none'
                        });
                    },
                });
                this.taskId = ret.taskId;
            },
            /**
             * 取消周期任务
             */
            testClearInterval: function() {
                console.log(this.taskId);
                clearIntervalTask(this.taskId);
            },
            testInputDialog() {
                getUserInput(function(res) {
                    console.log(res);
                });
            },
            testQuitApp() {
                quitApp()
            },
杜庆泉's avatar
杜庆泉 已提交
219 220 221 222 223 224 225 226 227
			testArrayConvert() {
				let convertRet = arrayConvert()
				if(convertRet){
					uni.showToast({
					    icon: "none",
					    title: '数组转换成功'
					});
				}
			},
Y
yurj26 已提交
228 229 230 231 232 233 234 235 236 237 238
            testMetaRead() {
                let ret = getMetaConfig();
                uni.showToast({
                    icon: "none",
                    title: '读取成功,注意查看控制台输出'
                });
                console.log(ret);
            }

        }
    }
杜庆泉's avatar
杜庆泉 已提交
239
</script>
杜庆泉's avatar
init  
杜庆泉 已提交
240

杜庆泉's avatar
杜庆泉 已提交
241
<style>
Y
yurj26 已提交
242 243 244 245 246 247
    @import '@/common/uni-uvue.css';

    .uni-container {
        min-height: 100%;
    }
</style>