CN-936 开发appearance页面:保存逻辑调整,及timezoneOffset设置方式修改

This commit is contained in:
hyx
2023-03-24 18:44:02 +08:00
parent 102f99e4f5
commit 5433006ebd
6 changed files with 148 additions and 149 deletions

View File

@@ -129,7 +129,7 @@ export default {
}) })
}, },
delBatch () { delBatch () {
let ids = [] const ids = []
if (this.batchDeleteObjs && this.batchDeleteObjs.length > 0) { if (this.batchDeleteObjs && this.batchDeleteObjs.length > 0) {
this.batchDeleteObjs.forEach(item => { this.batchDeleteObjs.forEach(item => {
ids.push(item.id) ids.push(item.id)

View File

@@ -57,10 +57,9 @@
</div> </div>
</template> </template>
<script> <script>
import { api,getDictList } from '@/utils/api' import { api } from '@/utils/api'
import { get, put } from '@/utils/http'
import { storageKey } from '@/utils/constants' import { storageKey } from '@/utils/constants'
import axios from 'axios'
export default { export default {
name: 'Appearance', name: 'Appearance',
@@ -111,22 +110,20 @@
this.initData() this.initData()
}, },
methods: { methods: {
async initData () { initData () {
this.dateFormatList.forEach(date => { this.dateFormatList.forEach(date => {
date.example = window.$dayJs(new Date()).tz().format(date.value) date.example = window.$dayJs(new Date()).tz().format(date.value)
}) })
await get(api.timezone).then(response => {
if (response.code === 200) {
this.timezoneList = response.data
}
})
axios.get(api.timezone).then(response => {
if (response.data.code === 200) {
this.timezoneList = response.data.data
if (this.timezoneList && this.timezoneList.length > 0) { if (this.timezoneList && this.timezoneList.length > 0) {
this.timezoneList.forEach(mapData => { this.timezoneList.forEach(mapData => {
let offset = Number(mapData.offset)/3600000 //转换为小 const offset = Number(mapData.offset) / 3600000 // 转换为小
mapData.timezoneOffset = offset mapData.timezoneOffset = offset
let hour = Math.abs(parseInt(offset)) const hour = Math.abs(parseInt(offset))
let offsetStr = offset.toString() const offsetStr = offset.toString()
let minute = 0 let minute = 0
if (offsetStr.indexOf('.') > -1) { if (offsetStr.indexOf('.') > -1) {
minute = Math.abs(Number(offsetStr.substring(offsetStr.indexOf('.'))) * 60) minute = Math.abs(Number(offsetStr.substring(offsetStr.indexOf('.'))) * 60)
@@ -152,18 +149,30 @@
} }
}) })
} }
get(this.url, { pageSize: -1 }).then(response => { }
if (response.code === 200) { })
this.appearanceObject = response.data
axios.get(this.url, { pageSize: -1 }).then(response => {
if (response.data.code === 200) {
this.appearanceObject = response.data.data
} }
}) })
}, },
save () { save () {
if (this.blockOperation.save) { return } if (this.blockOperation.save) { return }
this.blockOperation.save = true this.blockOperation.save = true
put(this.url, this.appearanceObject).then(response => { axios.put(this.url, this.appearanceObject).then(response => {
if (response.code === 200) { if (response.data.code === 200) {
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') }) this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
if (this.appearanceObject.date_format !== localStorage.getItem(storageKey.dateFormat)) {
localStorage.setItem(storageKey.dateFormat, this.appearanceObject.date_format)
}
if (this.appearanceObject.timezone !== localStorage.getItem(storageKey.sysTimezone)) {
localStorage.setItem(storageKey.sysTimezone, this.appearanceObject.timezone)
window.$dayJs.tz.setDefault(this.appearanceObject.timezone)
localStorage.setItem(storageKey.timezoneOffset, window.$dayJs.tz().utcOffset() / 60)
localStorage.setItem(storageKey.timezoneLocalOffset, dayjs().utcOffset() / 60)
}
} else { } else {
this.$message.error(response.message) this.$message.error(response.message)
} }
@@ -176,16 +185,6 @@
} }
}).finally(() => { }).finally(() => {
this.blockOperation.save = false this.blockOperation.save = false
if (this.appearanceObject.date_format !== localStorage.getItem(storageKey.dateFormat)) {
localStorage.setItem(storageKey.dateFormat, this.appearanceObject.date_format)
}
if (this.appearanceObject.timezone !== localStorage.getItem(storageKey.sysTimezone)) {
localStorage.setItem(storageKey.sysTimezone, this.appearanceObject.timezone)
}
let timezone = this.timezoneList.find(mapData => mapData.name === this.appearanceObject.timezone)
if (timezone.timezoneOffset !== localStorage.getItem(storageKey.timezoneOffset)) {
localStorage.setItem(storageKey.timezoneOffset, timezone.timezoneOffset)
}
}) })
} }
} }

View File

@@ -301,7 +301,7 @@ export default {
type: 'warning' type: 'warning'
}) })
} else { } else {
let curRecord = this.batchDeleteObjs[0] const curRecord = this.batchDeleteObjs[0]
this.initConfig(curRecord) this.initConfig(curRecord)
this.object = curRecord this.object = curRecord
this.rightBox.show = true this.rightBox.show = true