Optimize drawer loading in ThemeList

pull/3445/head
johnniang 2019-04-12 09:57:53 +08:00
parent 5cd0c59491
commit 534617d1f0
2 changed files with 89 additions and 39 deletions

6
package-lock.json generated
View File

@ -7791,6 +7791,12 @@
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
"dev": true "dev": true
}, },
"generate-asset-webpack-plugin": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/generate-asset-webpack-plugin/-/generate-asset-webpack-plugin-0.3.0.tgz",
"integrity": "sha1-ZmLvgDP21DMMeImBZGHOJWgxMxg=",
"dev": true
},
"get-caller-file": { "get-caller-file": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz",

View File

@ -1,6 +1,10 @@
<template> <template>
<page-view> <page-view>
<a-row :gutter="12" type="flex" align="middle"> <a-row
:gutter="12"
type="flex"
align="middle"
>
<a-col <a-col
class="theme-item" class="theme-item"
:xl="6" :xl="6"
@ -12,14 +16,29 @@
:key="index" :key="index"
> >
<a-card :bodyStyle="{ padding: '14px' }"> <a-card :bodyStyle="{ padding: '14px' }">
<img :alt="theme.name" :src="theme.screenshots" slot="cover"> <img
:alt="theme.name"
:src="theme.screenshots"
slot="cover"
>
<a-divider></a-divider> <a-divider></a-divider>
<div class="theme-control"> <div class="theme-control">
<span class="theme-title">{{ theme.name }}</span> <span class="theme-title">{{ theme.name }}</span>
<a-button-group class="theme-button"> <a-button-group class="theme-button">
<a-button type="primary" v-if="theme.activated" disabled>已启用</a-button> <a-button
<a-button type="primary" @click="activeTheme(theme.id)" v-else></a-button> type="primary"
<a-button @click="settingDrawer(theme.id)" v-if="theme.hasOptions"></a-button> v-if="theme.activated"
disabled
>已启用</a-button>
<a-button
type="primary"
@click="activeTheme(theme.id)"
v-else
>启用</a-button>
<a-button
@click="settingDrawer(theme)"
v-if="theme.hasOptions"
>设置</a-button>
</a-button-group> </a-button-group>
</div> </div>
</a-card> </a-card>
@ -34,9 +53,22 @@
:visible="visible" :visible="visible"
destroyOnClose destroyOnClose
> >
<a-row :gutter="12" type="flex"> <a-row
<a-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24"> :gutter="12"
<a-skeleton active :loading="optionLoading" :paragraph="{rows: 10}"> type="flex"
>
<a-col
:xl="12"
:lg="12"
:md="12"
:sm="24"
:xs="24"
>
<a-skeleton
active
:loading="optionLoading"
:paragraph="{rows: 10}"
>
<img <img
v-if="themeProperty" v-if="themeProperty"
:alt="themeProperty.name" :alt="themeProperty.name"
@ -45,12 +77,22 @@
> >
</a-skeleton> </a-skeleton>
</a-col> </a-col>
<a-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24"> <a-col
<a-skeleton active :loading="optionLoading" :paragraph="{rows: 20}"> :xl="12"
:lg="12"
:md="12"
:sm="24"
:xs="24"
>
<a-skeleton
active
:loading="optionLoading"
:paragraph="{rows: 20}"
>
<a-tabs defaultActiveKey="0"> <a-tabs defaultActiveKey="0">
<a-tab-pane <a-tab-pane
v-for="(group, index) in themeConfiguration" v-for="(group, index) in themeConfiguration"
:key="index" :key="index.toString()"
:tab="group.label" :tab="group.label"
> >
<a-form layout="vertical"> <a-form layout="vertical">
@ -96,11 +138,17 @@
</a-select> </a-select>
</a-form-item> </a-form-item>
<a-form-item> <a-form-item>
<a-button type="primary" @click="saveSettings"></a-button> <a-button
type="primary"
@click="saveSettings"
>保存</a-button>
</a-form-item> </a-form-item>
</a-form> </a-form>
</a-tab-pane> </a-tab-pane>
<a-tab-pane key="about" tab="关于"> <a-tab-pane
key="about"
tab="关于"
>
<a-form-item> <a-form-item>
<a-popconfirm <a-popconfirm
:title="'确定删除【' + themeProperty.name + '】主题?'" :title="'确定删除【' + themeProperty.name + '】主题?'"
@ -113,8 +161,8 @@
</a-form-item> </a-form-item>
</a-tab-pane> </a-tab-pane>
</a-tabs> </a-tabs>
<a-skeleton :loading="optionLoading"> </a-skeleton>
</a-skeleton></a-skeleton></a-col> </a-col>
</a-row> </a-row>
</a-drawer> </a-drawer>
</page-view> </page-view>
@ -123,12 +171,9 @@
<script> <script>
import { PageView } from '@/layouts' import { PageView } from '@/layouts'
import themeApi from '@/api/theme' import themeApi from '@/api/theme'
import { setTimeout } from 'timers'
export default { export default {
components: { components: { PageView },
PageView
},
data() { data() {
return { return {
optionLoading: true, optionLoading: true,
@ -140,9 +185,9 @@ export default {
}, },
themes: [], themes: [],
visible: false, visible: false,
themeConfiguration: {}, themeConfiguration: null,
themeSettings: {}, themeSettings: [],
themeProperty: {} themeProperty: null
} }
}, },
computed: { computed: {
@ -159,17 +204,21 @@ export default {
this.themes = response.data.data this.themes = response.data.data
}) })
}, },
settingDrawer(themeId) { settingDrawer(theme) {
this.visible = true this.visible = true
var that = this this.optionLoading = true
setTimeout(function() { this.themeProperty = theme
themeApi.fetchConfiguration(themeId).then(response => {
that.themeConfiguration = response.data.data setTimeout(() => {
that.loadSettings() themeApi.fetchConfiguration(theme.id).then(response => {
that.getThemeProperty(themeId) this.themeConfiguration = response.data.data
themeApi.fetchSettings().then(response => {
this.themeSettings = response.data.data
this.visible = true
this.optionLoading = false
}) })
that.optionLoading = false })
}, 500) }, 300)
}, },
activeTheme(theme) { activeTheme(theme) {
themeApi.active(theme).then(response => { themeApi.active(theme).then(response => {
@ -188,11 +237,6 @@ export default {
this.$message.success('保存成功!') this.$message.success('保存成功!')
}) })
}, },
loadSettings() {
themeApi.fetchSettings().then(response => {
this.themeSettings = response.data.data
})
},
getThemeProperty(themeId) { getThemeProperty(themeId) {
themeApi.getProperty(themeId).then(response => { themeApi.getProperty(themeId).then(response => {
this.themeProperty = response.data.data this.themeProperty = response.data.data
@ -200,9 +244,9 @@ export default {
}, },
onClose() { onClose() {
this.visible = false this.visible = false
this.themeConfiguration = {} this.optionLoading = false
this.themeProperty = {} this.themeConfiguration = null
this.optionLoading = true this.themeProperty = null
} }
} }
} }