component.uvue 8.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<template>
    <view class="uni-container">
        <view class="uni-header-logo">
            <image class="uni-header-image" src="/static/componentIndex.png"></image>
        </view>
        <view class="uni-hello-text">
            <text class="hello-text">uni-app内置组件,展示样式仅供参考,文档详见:</text>
            <u-link :href="'https://uniapp.dcloud.io/component/'" :text="'https://uniapp.dcloud.io/component/'"
                :inWhiteList="true"></u-link>
        </view>
        <view class="uni-panel" v-for="(item, index) in list" :key="item.id">
            <view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="triggerCollapse(index, item)">
                <text class="uni-panel-text" :class="item.enable == false ? 'text-disabled' : ''">{{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)">
                    <text class="uni-navigate-text"
20
                        :class="page.enable == false ? 'text-disabled' : ''">{{page.name}}</text>
21 22 23 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
                    <image :src="arrowRightIcon" class="uni-icon"></image>
                </view>
            </view>
        </view>
    </view>
</template>

<script lang="ts">
    type Page = {
        name : string,
        enable ?: boolean,
        url ?: string
    }
    type ListItem = {
        id : string,
        name : string,
        open : boolean,
        pages : Page[],
        url ?: string,
        enable ?: boolean
    }
    export default {
        data() {
            return {
                list: [{
                    id: 'view',
                    name: '视图容器',
                    open: false,
                    pages: [
                        {
                            name: 'view',
                        },
                        {
                            name: 'scroll-view',
                        },
                        {
                            name: 'swiper',
                        },
59
                        /*
60 61 62 63 64 65 66 67
                        {
                            name: 'movable-view',
                            enable: false
                        },
                        {
                            name: 'cover-view',
                            enable: false
                        },
68
                        */
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
69 70 71 72
						{
							name:'list(新闻)',
							url:"pages/component/list/list",
						},
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
73 74
						{
							name:'list',
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
75
							url:"pages/component/long-list/long-list",
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
						}
                    ] as Page[]
                }, {
                    id: 'content',
                    name: '基础内容',
                    open: false,
                    pages: [
                        {
                            name: 'text',
                        },
                        {
                            name: 'rich-text',
                            enable: false
                        },
                        {
                            name: 'progress',
                        }
                    ] as Page[]
                }, {
                    id: 'form',
                    name: '表单组件',
                    open: false,
                    pages: [
                        {
                            name: 'button',
                        },
                        {
                            name: 'checkbox',
                        },
105
                        /* {
106 107
                            name: 'form',
                            enable: false
108
                        }, */
109 110
                        {
                            name: 'input',
111
                        /* }, {
112 113 114 115
                            name: 'label',
                            enable: false
                        }, {
                            name: 'picker',
116
                            enable: false */
117 118 119 120 121 122 123 124 125 126 127 128 129 130
                        }, {
                            name: 'picker-view',
                            enable: false
                        }, {
                            name: 'radio',
                        }, {
                            name: 'slider',
                        }, {
                            name: 'slider-100',
                        },{
                            name: 'switch',
                        }, {
                            name: 'textarea',
                        },
131
                        /*
132 133 134 135
                        {
                            name: 'editor',
                            enable: false
                        },
136
                        */
137
                    ] as Page[]
138
                /* }, {
139 140 141 142 143 144
                    id: 'nav',
                    name: '导航',
                    open: false,
                    pages: [{
                        name: 'navigator',
                        enable: false
145
                    }] as Page[] */
146 147 148 149 150 151 152 153 154 155
                }, {
                    id: 'media',
                    name: '媒体组件',
                    open: false,
                    pages: [{
                        name: 'image',
                        enable: true
                    }, {
                        name: 'video',
                        enable: false
156 157 158
                    }, {
                        name: 'animation-view',
                        enable: false
159 160
                    }] as Page[]
                },
161
                /*
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
                {
                    id: 'map',
                    name: '地图',
                    open: false,
                    pages: [
                        {
                            name: 'map',
                            enable: false
                        }
                    ] as Page[]
                },
                {
                    id: 'canvas',
                    name: '画布',
                    open: false,
                    pages: [
                        {
                            name: 'canvas'
                        }
                    ] as Page[]
                },
183
                */
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
                {
                    id: 'web-view',
                    name: '网页',
                    open: false,
                    pages: [
                        {
                            name: '网络网页',
                            enable: true,
                            url: '/pages/component/web-view/web-view'
                        },
                        {
                            name: '本地网页',
                            enable: true,
                            url: '/pages/component/web-view-local/web-view-local'
                        }
                    ] as Page[]
                },
201
                /*
202 203 204 205 206 207 208 209
                {
                    id: 'ad',
                    url: 'ad',
                    name: 'AD组件',
                    enable: false,
                    open: false,
                    pages: [] as Page[]
                }
210
                */
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
                ] as ListItem[],
                arrowUpIcon: '/static/icons/arrow-up.png',
                arrowDownIcon: '/static/icons/arrow-down.png',
                arrowRightIcon: '/static/icons/arrow-right.png',
            }
        },
        methods: {
            triggerCollapse(index ?: number, item : ListItem) {
                if (item.pages.length == 0) {
                    const page : Page = {
                        name: item.name,
                        enable: item.enable,
                        url: item.url
                    }
                    this.goDetailPage(page);
                    return;
                }
                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 : Page) {
237
                if (e.enable == false) {
238
                    uni.showToast({
239 240
                        title: '暂不支持',
                        icon: 'none'
241 242 243 244 245 246 247 248 249 250 251 252 253 254
                    })
                    return
                }
                const url = e.url != null ? e.url! : `/pages/component/${e.name}/${e.name}`
                uni.navigateTo({
                    url
                })
            }
        }
    }
</script>

<style>
    @import '../../common/uni-uvue.css';
Y
init  
yurj26 已提交
255
</style>