PopSwitch.vue
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<template>
<a-popconfirm :placement="placement" :title="titleText" :ok-text="okText" :cancel-text="cancelText"
@confirm="myConfirm()" @openChange="visibleChange">
<a-switch v-model:checked="myChecked" :checked-children="checkedChildren" :un-checked-children="unCheckedChildren"/>
</a-popconfirm>
</template>
<script lang="ts">
import {message} from 'ant-design-vue';
import {Component, Prop, Watch} from "vue-facing-decorator";
import {PopConfirm} from "@/components/popconfirm/PopConfirm";
/**
* <PopSwitch @okConfirm="pagination.refresh()"
* :url="`notice/showTopNotice?noticeId=${record.noticeId}&showTop=`"
* :checked="record.showTop"/>
*/
@Component({
name: "MPopSwitch",
components: {}
})
export default class PopSwitch extends PopConfirm {
// switch默认值
@Prop({required: true}) checked: boolean;
// switch缓存值
private _checked: boolean;
// switch显示文本
myChecked = false;
ok = false;
created() {
this.setMyTitle();
}
@Watch('title', {deep: true, immediate: true})
titleChecked(val: any) {
this.titleText = val;
}
@Watch('checked', {deep: true, immediate: true})
watchChecked(val: any): void {
if (val !== undefined) {
this.myChecked = val;
this._checked = JSON.parse(JSON.stringify(val));
this.setMyTitle();
}
}
visibleChange(visible: any): void {
this.$emit('visibleChange', visible);
if (visible) {
this.setMyTitle();
} else if (!this.ok) {
this.myChecked = this._checked;
}
}
setMyTitle(): void {
if (!this.title || this.title === '') {
this.titleText = this.myChecked ? `您确定取消${this.checkedChildren}吗?` : `您确定${this.checkedChildren}吗?`;
}
}
/**
* 置顶
* @param record
*/
myConfirm(): void {
this.ok = true;
// @ts-ignore
this.axios.post(this.url + this.myChecked, null).then(() => {
message.success(this.myChecked ? this.checkedChildren + '成功' : '取消' + this.checkedChildren);
this.ok = false;
this.$emit('okConfirm');
});
}
}
</script>
<style>
</style>