fix:修改 时间问题

This commit is contained in:
zhangyu
2022-04-08 15:05:10 +08:00
parent 59584ce1b3
commit e081e151bf
3 changed files with 308 additions and 297 deletions

View File

@@ -34,12 +34,13 @@
</el-tabs> </el-tabs>
</el-form-item> </el-form-item>
<el-form-item label="Start at" prop="datepicker" v-if="whoshow" class="start_at"> <el-form-item label="Start at" prop="datepicker" v-if="whoshow" class="start_at">
<el-date-picker <my-date-picker
v-model="editBackup.datepicker[0]" v-model="editBackup.datepicker[0]"
type="date" type="date"
:format="timeFormatStrToDatePickFormat(dateFormatStr)"
placeholder="选择日期" placeholder="选择日期"
> >
</el-date-picker> </my-date-picker>
<el-time-picker <el-time-picker
:value-format="'HH:mm:ss'" :value-format="'HH:mm:ss'"
@@ -160,88 +161,88 @@
</template> </template>
<script> <script>
import bus from "@/libs/bus"; import bus from '@/libs/bus'
import { put } from "@/http"; import { put } from '@/http'
export default { export default {
name: "backupsBox", name: 'backupsBox',
props: { props: {
obj: { obj: {
type: Object, type: Object
}, }
}, },
data () { data () {
return { return {
editBackup: { editBackup: {
status: "", status: '',
checkDays: [], checkDays: [],
checkDay: [], checkDay: [],
timepicker: "", timepicker: '',
datepicker: "", datepicker: '',
retention: "", retention: '',
state: "", state: '',
schedule: { schedule: {
repeat: "", repeat: '',
stime: "", stime: '',
type: "", type: '',
nums: [], nums: []
}
}, },
}, whoshow: '',
whoshow: "", activeName: '',
activeName: "", dateFormatStr: localStorage.getItem('nz-default-dateFormat') ? localStorage.getItem('nz-default-dateFormat') : 'YYYY-MM-DD HH:ss:mm',
rules: { rules: {
type: [ type: [
{ {
required: true, required: true,
message: this.$t("validate.required"), message: this.$t('validate.required'),
trigger: "change", trigger: 'change'
}, }
], ],
datepicker: [ datepicker: [
{ {
required: true, required: true,
message: this.$t("validate.required"), message: this.$t('validate.required'),
trigger: "change", trigger: 'change'
}, }
], ],
checkDays: [ checkDays: [
{ {
required: true, required: true,
message: this.$t("validate.required"), message: this.$t('validate.required'),
trigger: "change", trigger: 'change'
}, }
], ],
retention: [ retention: [
{ {
required: true, required: true,
message: this.$t("validate.required"), message: this.$t('validate.required'),
trigger: ["blur", "change"], trigger: ['blur', 'change']
}, }
], ],
Status: [ Status: [
{ {
required: true, required: true,
message: this.$t("validate.required"), message: this.$t('validate.required'),
trigger: "change", trigger: 'change'
}, }
], ],
repeat: [ repeat: [
{ {
required: true, required: true,
message: this.$t("validate.required"), message: this.$t('validate.required'),
trigger: "blur", trigger: 'blur'
}, }
], ],
checkDay: [ checkDay: [
{ {
required: true, required: true,
message: this.$t("validate.required"), message: this.$t('validate.required'),
trigger: "change", trigger: 'change'
}
]
}, },
], week: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
},
week: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
month: [ month: [
1, 1,
2, 2,
@@ -274,15 +275,24 @@ export default {
29, 29,
30, 30,
31, 31,
"Last", 'Last'
], ]
}; }
}, },
components: {}, components: {},
computed: {}, computed: {},
created () {
const dateFormatStr = localStorage.getItem('nz-default-dateFormat')
if (dateFormatStr) {
this.dateFormatStr = dateFormatStr.split(' ')[0]
} else {
this.dateFormatStr = 'YYYY-MM-DD'
}
},
beforeMount () {}, beforeMount () {},
mounted () { mounted () {
@@ -292,88 +302,89 @@ export default {
changeCheck (item) { changeCheck (item) {
if (this.editBackup.type == 3) { if (this.editBackup.type == 3) {
let nums = []; const nums = []
this.editBackup.nums = []; this.editBackup.nums = []
for (let i in this.editBackup.checkDay) { for (const i in this.editBackup.checkDay) {
nums.push(Number(this.editBackup.checkDay[i]) + 1); nums.push(Number(this.editBackup.checkDay[i]) + 1)
} }
console.log(nums); console.log(nums)
this.editBackup.nums = nums; this.editBackup.nums = nums
} else if (this.editBackup.type == 4) { } else if (this.editBackup.type == 4) {
let nums = []; const nums = []
this.editBackup.nums = []; this.editBackup.nums = []
this.editBackup.checkDays.forEach((e, i) => { this.editBackup.checkDays.forEach((e, i) => {
if (e === 31) { if (e === 31) {
nums.push(-1); nums.push(-1)
} else { } else {
nums.push(Number(this.editBackup.checkDays[i]) + 1); nums.push(Number(this.editBackup.checkDays[i]) + 1)
} }
}); })
console.log(nums); console.log(nums)
this.editBackup.nums = nums; this.editBackup.nums = nums
} }
this.$forceUpdate(); this.$forceUpdate()
}, },
statusChange (item) { statusChange (item) {
this.$forceUpdate(); this.$forceUpdate()
console.log(item); console.log(item)
if (item) { if (item) {
this.editBackup.state = 1; this.editBackup.state = 1
this.$emit("statechange", true); this.$emit('statechange', true)
} else { } else {
this.editBackup.state = 0; this.editBackup.state = 0
this.$emit("statechange", false); this.$emit('statechange', false)
} }
}, },
save () { save () {
console.log(this.editBackup); console.log(this.editBackup)
this.editBackup.stime = this.editBackup.datepicker.join(" "); this.editBackup.stime = this.editBackup.datepicker.join(' ')
put("/sys/backup", { this.editBackup.stime = this.timezoneToUtcTime(this.editBackup.stime) // 将本地时间转 utc时间
put('/sys/backup', {
state: Number(this.editBackup.state), state: Number(this.editBackup.state),
schedule: { schedule: {
type: Number(this.editBackup.type), type: Number(this.editBackup.type),
stime: this.editBackup.stime, stime: this.editBackup.stime,
repeat: Number(this.editBackup.repeat), repeat: Number(this.editBackup.repeat),
nums: this.editBackup.nums, nums: this.editBackup.nums
}, },
retention: Number(this.editBackup.retention), retention: Number(this.editBackup.retention)
}).then((res) => { }).then((res) => {
if (res.code === 200) { if (res.code === 200) {
this.esc(true); this.esc(true)
} }
}); })
}, },
inputchange (n) { inputchange (n) {
this.$forceUpdate(); this.$forceUpdate()
}, },
datasourceChange (tab) { datasourceChange (tab) {
console.log(tab.name); console.log(tab.name)
switch (tab.name) { switch (tab.name) {
case "2": case '2':
this.whoshow = 2; this.whoshow = 2
break; break
case "1": case '1':
this.whoshow = 1; this.whoshow = 1
break; break
case "3": case '3':
this.whoshow = 3; this.whoshow = 3
break; break
case "4": case '4':
this.whoshow = 4; this.whoshow = 4
break; break
} }
console.log(this.whoshow); console.log(this.whoshow)
console.log(this.editBackup); console.log(this.editBackup)
this.$forceUpdate(); this.$forceUpdate()
}, },
clickOutside () { clickOutside () {
this.esc(false); this.esc(false)
}, },
/* 关闭弹框 */ /* 关闭弹框 */
esc (refresh) { esc (refresh) {
this.$emit("close", refresh); this.$emit('close', refresh)
}, }
}, },
watch: { watch: {
@@ -382,116 +393,118 @@ export default {
immediate: true, immediate: true,
handler (n) { handler (n) {
// debugger // debugger
console.log(n); console.log(n)
this.editBackup = JSON.parse(JSON.stringify(n)); this.editBackup = JSON.parse(JSON.stringify(n))
this.editBackup.checkDay = []; this.editBackup.checkDay = []
this.editBackup.checkDays = []; this.editBackup.checkDays = []
this.editBackup.type = this.editBackup.type + ""; this.editBackup.type = this.editBackup.type + ''
let stime = this.editBackup.stime; const stime1 = this.utcTimeToTimezoneStr(this.editBackup.stime)
let time = stime.split(" "); const stime = this.utcTimeToTimezone(this.editBackup.stime)
this.$set(this.editBackup, "datepicker", time); const time = stime1.split(' ')
console.log("obj", this.editBackup); time[0] = stime
this.$set(this.editBackup, 'datepicker', time)
console.log('obj', this.editBackup)
if (this.editBackup.state == 1) { if (this.editBackup.state == 1) {
this.editBackup.status = true; this.editBackup.status = true
this.$emit("statechange", true); this.$emit('statechange', true)
} else { } else {
this.editBackup.status = false; this.editBackup.status = false
this.$emit("statechange", false); this.$emit('statechange', false)
} }
switch (this.editBackup.type) { switch (this.editBackup.type) {
case "1": case '1':
this.activeName = "1"; this.activeName = '1'
this.whoshow = 1; this.whoshow = 1
break; break
case "2": case '2':
this.activeName = "2"; this.activeName = '2'
this.whoshow = 2; this.whoshow = 2
break; break
case "3": case '3':
this.activeName = "3"; this.activeName = '3'
this.whoshow = 3; this.whoshow = 3
break; break
case "4": case '4':
this.activeName = "4"; this.activeName = '4'
this.whoshow = 4; this.whoshow = 4
break; break
} }
let checkdays = []; const checkdays = []
this.checkDay = []; this.checkDay = []
if (this.editBackup.type == 3) { if (this.editBackup.type == 3) {
this.editBackup.nums.forEach((e) => { this.editBackup.nums.forEach((e) => {
checkdays.push(e - 1); checkdays.push(e - 1)
if (e === -1) { if (e === -1) {
checkdays.push(6); checkdays.push(6)
} }
}); })
// for (let i in checkdays) { // for (let i in checkdays) {
// this.checkDay.push(this.week[i]); // this.checkDay.push(this.week[i]);
// } // }
this.$set(this.editBackup, "checkDay", checkdays); this.$set(this.editBackup, 'checkDay', checkdays)
// this.editBackup.checkDay = checkdays // this.editBackup.checkDay = checkdays
} else if (this.editBackup.type == 4) { } else if (this.editBackup.type == 4) {
this.editBackup.nums.forEach((e) => { this.editBackup.nums.forEach((e) => {
if (e === -1) { if (e === -1) {
checkdays.push(31); checkdays.push(31)
} else { } else {
checkdays.push(e - 1); checkdays.push(e - 1)
} }
}); })
this.$set(this.editBackup, "checkDays", checkdays); this.$set(this.editBackup, 'checkDays', checkdays)
} }
console.log("editBackupNow", this.editBackup); console.log('editBackupNow', this.editBackup)
// this.$nextTick(() => { // this.$nextTick(() => {
// this.$forceUpdate(); // this.$forceUpdate();
// }); // });
this.$forceUpdate(); this.$forceUpdate()
},
},
"editBackup.status": {
deep: true,
handler(n) {
console.log(n);
if (n) {
this.editBackup.state = 1;
this.editBackup.status = n;
this.$emit("statechange", true);
} else {
this.editBackup.state = 0;
this.editBackup.status = n;
this.$emit("statechange", false);
} }
}, },
}, 'editBackup.status': {
"editBackup.checkDay": {
deep: true, deep: true,
handler (n) { handler (n) {
console.log(n); console.log(n)
if (n) {
this.editBackup.state = 1
this.editBackup.status = n
this.$emit('statechange', true)
} else {
this.editBackup.state = 0
this.editBackup.status = n
this.$emit('statechange', false)
}
}
},
'editBackup.checkDay': {
deep: true,
handler (n) {
console.log(n)
n.forEach((e, i) => { n.forEach((e, i) => {
if (e === 6) { if (e === 6) {
this.editBackup.checkDay[i] = -1; this.editBackup.checkDay[i] = -1
} }
}); })
let nums = []; const nums = []
this.editBackup.nums = []; this.editBackup.nums = []
this.editBackup.checkDay.forEach((e, i) => { this.editBackup.checkDay.forEach((e, i) => {
nums.push(Number(i) + 1); nums.push(Number(i) + 1)
}); })
this.editBackup.nums = nums; this.editBackup.nums = nums
console.log("checkDay", this.editBackup.checkDay); console.log('checkDay', this.editBackup.checkDay)
}
}, },
}, 'editBackup.datepicker': {
"editBackup.datepicker": {
deep: true, deep: true,
handler (n) { handler (n) {
this.editBackup.datepicker[0] = bus.timeFormate( this.editBackup.datepicker[0] = bus.timeFormate(
new Date(n[0]), new Date(n[0]),
"YYYY-MM-DD" 'YYYY-MM-DD'
); )
}, }
}, }
// "editBackup.checkDays": { // "editBackup.checkDays": {
// deep: true, // deep: true,
// handler(n) { // handler(n) {
@@ -503,8 +516,8 @@ export default {
// console.log("checkDays", this.editBackup.checkDays); // console.log("checkDays", this.editBackup.checkDays);
// }, // },
// }, // },
}, }
}; }
</script> </script>
<style lang='' scoped> <style lang='' scoped>
</style> </style>

View File

@@ -20,7 +20,7 @@
{{ tableData[0].retention }} {{ tableData[0].retention }}
</span> </span>
<span v-if="item.prop === 'last'"> <span v-if="item.prop === 'last'">
{{ tableData[0].schedule && tableData[0].schedule.stime }} {{ tableData[0].schedule && utcTimeToTimezoneStr(tableData[0].schedule.stime) }}
</span> </span>
<span v-if="item.prop === 'state'"> <span v-if="item.prop === 'state'">
<el-switch class="switch" v-model="switchStatus"> </el-switch> <el-switch class="switch" v-model="switchStatus"> </el-switch>
@@ -79,43 +79,43 @@
</template> </template>
<script> <script>
import { get, post } from "@/http"; import { get, post } from '@/http'
import lodash from "lodash"; import lodash from 'lodash'
import bus from "@/libs/bus"; import bus from '@/libs/bus'
export default { export default {
name: "backupsTable", name: 'backupsTable',
mixins: [], mixins: [],
props: { props: {
loading: Boolean, loading: Boolean,
customTableTitle: Array, customTableTitle: Array,
isConfigurations: Boolean, isConfigurations: Boolean,
isState: Boolean, isState: Boolean
}, },
data () { data () {
return { return {
switchStatus: true, switchStatus: true,
tableData: [ tableData: [
{ {
retention: "", retention: '',
state: "", state: '',
schedule: { schedule: {
repeat: "", repeat: '',
stime: "", stime: '',
type: "", type: '',
nums: [], nums: []
}, }
}, }
], ],
tableData2: [ tableData2: [
{ {
fileName: "", fileName: '',
time: "", time: '',
size: "", size: ''
}, }
], ]
}; }
}, },
components: {}, components: {},
@@ -125,75 +125,74 @@ export default {
created () {}, created () {},
mounted () { mounted () {
this.getTableData(); this.getTableData()
this.monitoring() this.monitoring()
}, },
methods: { methods: {
monitoring () { monitoring () {
this.$on('getData', (res) => { this.$on('getData', (res) => {
console.log('getdata'); console.log('getdata')
this.getTableData() this.getTableData()
window.location.reload() window.location.reload()
}) })
}, },
async getTableData () { async getTableData () {
await get("/sys/backup").then((res) => { await get('/sys/backup').then((res) => {
if (res.code === 200) { if (res.code === 200) {
if (res.data) { if (res.data) {
this.tableData[0].retention = res.data.retention; this.tableData[0].retention = res.data.retention
this.tableData[0].state = res.data.state; this.tableData[0].state = res.data.state
this.switchStatus = res.data.state === 1 ? true : false; this.switchStatus = res.data.state === 1
for (let i in res.data.schedule) { for (const i in res.data.schedule) {
this.tableData[0].schedule[i] = res.data.schedule[i]; this.tableData[0].schedule[i] = res.data.schedule[i]
} }
} }
} }
}); })
await post("/sys/backup/list").then((res) => { await post('/sys/backup/list').then((res) => {
if (res.code === 200) { if (res.code === 200) {
if (res.data) { if (res.data) {
for (let i in res.data) { for (const i in res.data) {
this.tableData2[i].fileName = res.data[i].fileName; this.tableData2[i].fileName = res.data[i].fileName
this.tableData2[i].size = bus.getNumStr(res.data[i].size); this.tableData2[i].size = bus.getNumStr(res.data[i].size)
this.tableData2[i].time = res.data[i].time; this.tableData2[i].time = res.data[i].time
} }
} }
} }
}); })
}, },
backupNow (item) { backupNow (item) {
post("/sys/backup").then((res) => { post('/sys/backup').then((res) => {
console.log(res); console.log(res)
}); })
}, },
tableOperation (command) { tableOperation (command) {
if (command) { if (command) {
if (command === "edit") { if (command === 'edit') {
this.$emit("edit", this.tableData[0]); this.$emit('edit', this.tableData[0])
} else if (command === "del") { } else if (command === 'del') {
}
} }
} }
},
}, },
watch: { watch: {
isState: { isState: {
deep: true, deep: true,
handler (n) { handler (n) {
this.switchStatus = n; this.switchStatus = n
this.tableData[0].state = n === true ? 1 : 0; this.tableData[0].state = n === true ? 1 : 0
}, }
}, },
switchStatus: { switchStatus: {
deep: true, deep: true,
handler (n) { handler (n) {
this.tableData[0].state = n=== true ? 1 : 0; this.tableData[0].state = n === true ? 1 : 0
}
}
} }
} }
},
};
</script> </script>
<style lang='' scoped> <style lang='' scoped>
</style> </style>

View File

@@ -48,47 +48,46 @@
</template> </template>
<script> <script>
import nzDataList from "@/components/common/table/nzDataList"; import nzDataList from '@/components/common/table/nzDataList'
import backupsTable from "@/components/common/table/settings/backupsTable"; import backupsTable from '@/components/common/table/settings/backupsTable'
import backupsBox from '@/components/common/rightBox/administration/backupsBox' import backupsBox from '@/components/common/rightBox/administration/backupsBox'
export default { export default {
name: "backups", name: 'backups',
mixins: [], mixins: [],
props: [""], props: [''],
data () { data () {
return { return {
url: "/sys/backup/list", url: '/sys/backup/list',
customTableTitle: [ customTableTitle: [
{ label: "Frequency", prop: "repeat" }, { label: 'Frequency', prop: 'repeat' },
{ label: "Backup Retention", prop: "retention" }, { label: 'Backup Retention', prop: 'retention' },
{ label: "Last backup at", prop: "last" }, { label: 'Last backup at', prop: 'last' },
{ label: "Enable", prop: "state" }, { label: 'Enable', prop: 'state' }
], ],
customTableTitle2: [ customTableTitle2: [
{ label: "Date", prop: "time" }, { label: 'Date', prop: 'time' },
{ label: "File", prop: "fileName" }, { label: 'File', prop: 'fileName' },
{ label: "Size", prop: "size" }, { label: 'Size', prop: 'size' },
{ label: "Description", prop: "Description" }, { label: 'Description', prop: 'Description' }
], ],
tableData: [ tableData: [
{ {
retention: "", retention: '',
state: "", state: '',
schedule: {}, schedule: {}
}, }
], ],
tableData2: [ tableData2: [
{ {
list: {}, list: {}
}, }
], ],
rightBoxshow: false, rightBoxshow: false,
isState: '', isState: '',
isRefresh: '' isRefresh: ''
}; }
}, },
components: { nzDataList, backupsTable, backupsBox }, components: { nzDataList, backupsTable, backupsBox },
@@ -102,9 +101,9 @@ export default {
methods: { methods: {
edit (row) { edit (row) {
this.object = { ...row } this.object = { ...row }
this.object.name = `Edit backup configurations` this.object.name = 'Edit backup configurations'
if (this.object.schedule) { if (this.object.schedule) {
for(let i in this.object.schedule){ for (const i in this.object.schedule) {
this.object[i] = this.object.schedule[i] this.object[i] = this.object.schedule[i]
} }
} }
@@ -121,6 +120,6 @@ export default {
} }
}, },
watch: {}, watch: {}
}; }
</script> </script>