<template>
<el-form label-width="200px" style="max-width: 600px">
<el-divider>SWITCH</el-divider>
<el-form-item :label="'Switch Bool(' + switchBool + ')'">
<CellEdit v-model="switchBool" type="switch" :editable="editable" :call-save="saveSuccess" />
</el-form-item>
<el-form-item :label="'Switch Number(' + switchNumber + ')'">
<CellEdit v-model="switchNumber" type="switch" :editable="editable" :call-save="saveFailure" />
</el-form-item>
<el-form-item label="object switch1">
<CellEdit v-model="res.switchBool1" type="switch" :editable="editable" :call-save="saveFailure" />
</el-form-item>
<el-form-item label="object switch2">
<CellEdit v-model="res.switchBool2" type="switch" :editable="editable" :call-save="saveSuccess" />
</el-form-item>
<el-form-item label="object switch3">
<CellEdit v-model="res.switchBool3" type="switch" :editable="editable" :call-save="saveSuccess" />
</el-form-item>
<el-divider>TEXT</el-divider>
<el-form-item :label="'Text:(' + textSuccess + ')'">
<CellEdit v-model="textSuccess" type="text" :editable="editable" :call-save="saveSuccess" />
</el-form-item>
<el-form-item :label="'Text:(' + textFailure + ')'">
<CellEdit v-model="textFailure" type="text" :editable="editable" :call-save="saveFailure" />
</el-form-item>
<el-form-item label="Object Success">
<CellEdit v-model="res.textSuccess" type="text" :editable="editable" :call-save="saveSuccess" />
</el-form-item>
<el-form-item label="Object Failure">
<CellEdit v-model="res.textFailure" type="text" :editable="editable" :call-save="saveFailure" />
</el-form-item>
<el-divider>NUMBER</el-divider>
<el-form-item :label="'Number:(' + numberSuccess + ')'">
<CellEdit v-model="numberSuccess" type="number" :editable="editable" :call-save="saveSuccess" />
</el-form-item>
<el-form-item :label="'Number:(' + numberFailure + ')'">
<CellEdit v-model="numberFailure" type="number" :editable="editable" :call-save="saveFailure" />
</el-form-item>
<el-form-item label="Object Success">
<CellEdit v-model="res.numberSuccess" type="number" :editable="editable" :call-save="saveSuccess" />
</el-form-item>
<el-form-item label="Object Failure">
<CellEdit v-model="res.numberFailure" type="number" :editable="editable" :call-save="saveFailure" />
</el-form-item>
<el-divider>TEXTAREA</el-divider>
<el-form-item :label="'Textarea:(' + textareaSuccess + ')'">
<CellEdit v-model="textareaSuccess" type="textarea" :editable="editable" :call-save="saveSuccess" />
</el-form-item>
<el-form-item :label="'Textarea:(' + textareaFailure + ')'">
<CellEdit v-model="textareaFailure" type="textarea" :editable="editable" :call-save="saveFailure" />
</el-form-item>
<el-form-item label="Object Success">
<CellEdit v-model="res.textareaSuccess" type="textarea" :editable="editable" :call-save="saveSuccess" />
</el-form-item>
<el-form-item label="Object Failure">
<CellEdit v-model="res.textareaFailure" type="textarea" :editable="editable" :call-save="saveFailure" />
</el-form-item>
<el-divider>SELECT</el-divider>
<el-form-item :label="'Select:(' + selectSuccess + ')'">
<CellEdit v-model="selectSuccess" type="select" :editable="editable" :ops="{
options: {
'beijing': '北京',
'shanghai': '上海',
'chengdu': '成都',
}
}" :call-save="saveSuccess" />
</el-form-item>
<el-form-item :label="'Select:(' + selectFailure + ')'">
<CellEdit v-model="selectFailure" type="select" :editable="editable" :ops="{
options: {
'beijing': '北京',
'shanghai': '上海',
'chengdu': '成都',
}
}" :call-save="saveFailure" />
</el-form-item>
<el-form-item label="Object Success">
<CellEdit v-model="res.selectSuccess" type="select" :select-use-empty="true" :editable="editable" :ops="{
options: {
'beijing': '北京',
'shanghai': '上海',
'chengdu': '成都',
}
}" :call-save="saveSuccess" />
</el-form-item>
<el-form-item label="Object Failure">
<CellEdit v-model="res.selectFailure" type="select" :select-use-empty="true" :editable="editable" :ops="{
options: {
'beijing': '北京',
'shanghai': '上海',
'chengdu': '成都',
}
}" :call-save="saveFailure" />
</el-form-item>
<el-form-item>
<el-button @click="handleSwitchEditable">切换编辑状态 {{ editable }}</el-button>
</el-form-item>
</el-form>
<hr>
<p>{{ res }}</p>
</template>
<script lang="ts" setup>
import "@qingbing/ts-v3-cell-edit/dist/style.css";
import type { TCellEditCallSave } from "@qingbing/ts-v3-cell-edit";
import { CellEdit } from "@qingbing/ts-v3-cell-edit";
import { reactive, ref } from 'vue'
import { ExMessage } from "@qingbing/ts-v3-element-plus";
// 对象属性传递
const res = reactive({
switchBool1: 1,
switchBool2: 1,
switchBool3: true,
textSuccess: "success",
textFailure: "failure",
numberSuccess: 1,
numberFailure: 0,
textareaSuccess: "success",
textareaFailure: "failure",
selectSuccess: "shanghai",
selectFailure: "shanghai",
})
// 控制是否可编辑
const editable = ref(true)
const handleSwitchEditable = () => {
editable.value = !editable.value
}
// switch
const switchBool = ref(true)
const switchNumber = ref(1)
// text
const textSuccess = ref("success")
const textFailure = ref("failure")
// number
const numberSuccess = ref(1)
const numberFailure = ref(0)
// textarea
const textareaSuccess = ref("success")
const textareaFailure = ref("failure")
// select
const selectSuccess = ref("shanghai")
const selectFailure = ref("shanghai")
// 保存成功函数示例
const saveSuccess: TCellEditCallSave = (callback: (status?: boolean) => void,
value: any,
params: any
) => {
ExMessage.success("哦业,保存成功了")
console.log(value, params);
callback(true)
}
// 保存失败函数示例
const saveFailure: TCellEditCallSave = (callback: (status?: boolean) => void,
value: any,
params: any
) => {
ExMessage.error("哦河,保存失败了")
console.log(value, params);
callback(false)
}
</script>