Skip to content

Commit

Permalink
修复 config 设置没有保存在浏览器数据库的问题 #Closes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
409915016 committed Oct 8, 2020
1 parent 12c1ec6 commit d8b7fae
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
20 changes: 18 additions & 2 deletions src/models/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { bucketName, qiniuBucketDomainName, qiniuAccessKey, qiniuSecretKey, qini
// 本地存在 核心配置数据 filmy:config 吗?
// 存在 则获取本地数据
// 不存在 则通过七牛云下载 config.json 然后保存在本地 filmy:config
let _temp_config;

const Config = {
load (silent = false) {
Expand All @@ -17,7 +18,7 @@ const Config = {
// 从数据库中获取核心配置数据
return min.hgetall(`${bucketName}:config`)
} else {
return filmyBucket.getFile(`config.json`)
return filmyBucket.getFile(`config.json?${new Date().getTime()}`)
.then(body => {
return Promise.resolve(JSON.parse(body))
})
Expand Down Expand Up @@ -68,7 +69,6 @@ const Config = {
for (const key of Object.keys(update)) {
config[key] = update[key]
}

const fileData = new Blob([JSON.stringify(config)], {type: 'application/json'})
fileData.name = 'config.json'

Expand All @@ -80,6 +80,22 @@ const Config = {
}
)
})
.then(({hash, key, config})=>{
config = config || {}

for (const key of Object.keys(update)) {
config[key] = update[key]
}

if(hash && key) {
try {
min.hmset(`${bucketName}:config`, config)
} catch (err) {
console.error(err)
}
}
return config
})
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/pages/init/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ new Vue({
},

mounted () {
Config.load(true)
.then(config => {
if (!config) return
const url = `${ location.protocol }//${ location.host }`
// Config.load(true)
// .then(config => {
// if (!config) return
// const url = `${ location.protocol }//${ location.host }`

openSimpleModal(
'Warning',
'This Filmy is already inited.',
`<a href="${ url }" class="btn btn-primary" role="button">OK</a>`
)
// openSimpleModal(
// 'Warning',
// 'This Filmy is already inited.',
// `<a href="${ url }" class="btn btn-primary" role="button">OK</a>`
// )

this.$el.remove()
})
// this.$el.remove()
// })
},

methods: {
Expand Down
14 changes: 6 additions & 8 deletions src/router-components/admin/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
<script>
import swal from 'sweetalert'
import Vue from 'vue'
import filmyBucket from '../../models/qiniu-bucket'
import Config from '../../models/Config'
import openSimpleModal from '../../libs/simple-modal'
import filmyBucket from '@/models/qiniu-bucket'
import Config from '@/models/Config'
import openSimpleModal from '@/libs/simple-modal'
export default {
data () {
return {
Expand All @@ -64,9 +65,7 @@
defaultConfig: {}
}
},
mounted: function () {
this.$nextTick(function () {
})
beforeMount: function () {
Config.load()
.then(config => {
this.defaultConfig = config
Expand Down Expand Up @@ -97,7 +96,6 @@
.then(putToken => {
switch (this.background) {
case 'url':
console.log(this.background_url)
return this.background_url
// break
case 'file':
Expand Down Expand Up @@ -136,5 +134,5 @@
</script>

<style scoped>
@import url('https://cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css');
</style>

0 comments on commit d8b7fae

Please sign in to comment.