155 lines
3.7 KiB
TypeScript
155 lines
3.7 KiB
TypeScript
import { ref, h } from "vue";
|
|
import editForm from "./form.vue";
|
|
import {
|
|
queryBanUserList,
|
|
banUserByIpData,
|
|
unbanUserByIp
|
|
} from "@/api/modules/newuserList";
|
|
import { message } from "@/utils/message";
|
|
import { addDialog } from "@/components/ReDialog";
|
|
export function useData() {
|
|
const formRef = ref();
|
|
const loading = ref(true);
|
|
const tableList = ref([]);
|
|
const isShow = ref(false);
|
|
const pagination = ref({
|
|
total: 0,
|
|
pageSize: 10,
|
|
pageSizes: [10, 20, 50, 100],
|
|
currentPage: 1,
|
|
background: true
|
|
});
|
|
const searchForm = ref({
|
|
seach_value: ""
|
|
});
|
|
const searchLabel = ref([
|
|
{ label: "IP/设备号", prop: "seach_value", type: "input" }
|
|
]);
|
|
const tableLabel = ref([
|
|
{
|
|
label: "Id",
|
|
prop: "id"
|
|
},
|
|
{
|
|
label: "类型",
|
|
prop: "type_str"
|
|
},
|
|
{
|
|
label: "IP/设备号",
|
|
prop: "type_text"
|
|
},
|
|
{
|
|
label: "状态",
|
|
prop: "status_str"
|
|
},
|
|
{
|
|
label: "禁用时间",
|
|
prop: "block_time"
|
|
},
|
|
{
|
|
label: "操作",
|
|
fixed: "right",
|
|
slot: "operation"
|
|
}
|
|
]);
|
|
const detailData = ref(null)
|
|
const onSearch = async (formData) => {
|
|
loading.value = true;
|
|
searchForm.value = { ...formData }
|
|
const { data, code } = await queryBanUserList({
|
|
...formData,
|
|
page: pagination.value.currentPage,
|
|
page_limit: pagination.value.pageSize,
|
|
|
|
});
|
|
if (code) {
|
|
detailData.value = data;
|
|
tableList.value = data.lists;
|
|
pagination.value.total = data.count;
|
|
pagination.value.currentPage = data.page;
|
|
}
|
|
loading.value = false;
|
|
};
|
|
const handleSizeChange = (val: number) => {
|
|
pagination.value.pageSize = val;
|
|
onSearch(searchForm.value);
|
|
};
|
|
const handleCurrentChange = (val: number) => {
|
|
pagination.value.currentPage = val;
|
|
onSearch(searchForm.value);
|
|
};
|
|
const openDialog = (title = "新增", rowData: any) => {
|
|
addDialog({
|
|
title: `${title}禁用IP/设备号`,
|
|
props: {
|
|
formInline: {
|
|
type: rowData?.type ?? 2,
|
|
type_text: '',
|
|
block_time: ''
|
|
}
|
|
},
|
|
width: "40%",
|
|
closeOnClickModal: false,
|
|
contentRenderer: () => h(editForm, { ref: formRef, formInline: null }),
|
|
beforeSure: (done, { options }) => {
|
|
const FormRef = formRef.value.getRef();
|
|
const curData = options.props.formInline;
|
|
delete curData.higherMenuOptions;
|
|
const saveData = async form => {
|
|
// console.log(form)
|
|
const formData = {
|
|
type: form.type,
|
|
type_text: form.type_text,
|
|
block_time: form.typeTimeType === 0 ? 0 : form.block_time
|
|
}
|
|
// console.log(formData)
|
|
const { code, msg } = await banUserByIpData(formData);
|
|
if (code) {
|
|
message("新增成功", { type: "success" });
|
|
onSearch(searchForm.value);
|
|
done();
|
|
} else {
|
|
message(msg, { type: "error" });
|
|
}
|
|
};
|
|
FormRef.validate(valid => {
|
|
if (valid) {
|
|
if (title === "新增") {
|
|
saveData(curData);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
};
|
|
// 禁用
|
|
const handleBanData = async rowData => {
|
|
const { code, msg } = await unbanUserByIp({ id: rowData.id });
|
|
if (code) {
|
|
message(`操作成功`, {
|
|
type: "success"
|
|
});
|
|
onSearch(searchForm.value);
|
|
} else {
|
|
message(msg, {
|
|
type: "error"
|
|
});
|
|
}
|
|
};
|
|
return {
|
|
searchForm,
|
|
searchLabel,
|
|
onSearch,
|
|
isShow,
|
|
tableList,
|
|
tableLabel,
|
|
pagination,
|
|
handleSizeChange,
|
|
handleCurrentChange,
|
|
loading,
|
|
handleBanData,
|
|
openDialog,
|
|
detailData
|
|
};
|
|
}
|