import { ao as vLoading, w as ElForm, x as ElFormItem, y as ElInput, h as ElButton, E as ElMessage, T as ElCard } from "./element-plus.CkEW9frc.js"; import { l as httpRequest } from "./index.CMd5bD1r.js"; import { J as defineComponent, t as onMounted, S as openBlock, _ as createElementBlock, a6 as withDirectives, T as createBlock, a0 as withCtx, $ as createVNode, a9 as createTextVNode, a1 as createBaseVNode, r as ref, ak as reactive } from "./.pnpm.BW3P1y8f.js"; import { _ as _export_sfc } from "./_plugin-vue_export-helper.1tPrXgE0.js"; import "./codemirror.CvJAcn2d.js"; const API_PATH = "/yifan/yifan_about_us"; const YifanAboutUsAPI = { // 列表查询 listYifanAboutUs(query) { return httpRequest({ url: `${API_PATH}/list`, method: "get", params: query }); }, // 详情查询 detailYifanAboutUs(id) { return httpRequest({ url: `${API_PATH}/detail/${id}`, method: "get" }); }, // 新增 createYifanAboutUs(body) { return httpRequest({ url: `${API_PATH}/create`, method: "post", data: body }); }, // 修改(带主键) updateYifanAboutUs(id, body) { return httpRequest({ url: `${API_PATH}/update/${id}`, method: "put", data: body }); }, // 删除(支持批量) deleteYifanAboutUs(ids) { return httpRequest({ url: `${API_PATH}/delete`, method: "delete", data: ids }); }, // 批量启用/停用 batchYifanAboutUs(body) { return httpRequest({ url: `${API_PATH}/available/setting`, method: "patch", data: body }); }, // 导出 exportYifanAboutUs(query) { return httpRequest({ url: `${API_PATH}/export`, method: "post", data: query, responseType: "blob" }); }, // 下载导入模板 downloadTemplateYifanAboutUs() { return httpRequest({ url: `${API_PATH}/download/template`, method: "post", responseType: "blob" }); }, // 导入 importYifanAboutUs(body) { return httpRequest({ url: `${API_PATH}/import`, method: "post", data: body, headers: { "Content-Type": "multipart/form-data" } }); } }; const _hoisted_1 = { class: "app-container" }; const _sfc_main = /* @__PURE__ */ defineComponent({ ...{ name: "YifanAboutUs", inheritAttrs: false }, __name: "index", setup(__props) { const dataFormRef = ref(); const loading = ref(false); const formData = reactive({ id: void 0, title: void 0, content: void 0 }); const rules = reactive({ title: [{ required: true, message: "请输入标题", trigger: "blur" }], content: [{ required: true, message: "请输入内容", trigger: "blur" }] }); async function loadData() { loading.value = true; try { const response = await YifanAboutUsAPI.listYifanAboutUs({ page_no: 1, page_size: 1 }); const items = response.data.data.items; if (items && items.length > 0) { const data = items[0]; formData.id = data.id; formData.title = data.title; formData.content = data.content; } } catch (error) { console.error(error); } finally { loading.value = false; } } function handleReset() { loadData(); } async function handleSubmit() { dataFormRef.value.validate(async (valid) => { if (valid) { loading.value = true; try { if (formData.id) { await YifanAboutUsAPI.updateYifanAboutUs(formData.id, formData); } else { const response = await YifanAboutUsAPI.createYifanAboutUs(formData); formData.id = response.data.data.id; } ElMessage.success("保存成功"); } catch (error) { console.error(error); } finally { loading.value = false; } } }); } onMounted(() => { loadData(); }); return (_ctx, _cache) => { const _component_el_input = ElInput; const _component_el_form_item = ElFormItem; const _component_el_button = ElButton; const _component_el_form = ElForm; const _component_el_card = ElCard; const _directive_loading = vLoading; return openBlock(), createElementBlock("div", _hoisted_1, [ withDirectives((openBlock(), createBlock(_component_el_card, null, { header: withCtx(() => [..._cache[2] || (_cache[2] = [ createBaseVNode("div", { class: "card-header" }, [ createBaseVNode("span", null, "品牌介绍") ], -1) ])]), default: withCtx(() => [ createVNode(_component_el_form, { ref_key: "dataFormRef", ref: dataFormRef, model: formData, rules, "label-suffix": ":", "label-width": "100px", "label-position": "right", style: { "max-width": "800px" } }, { default: withCtx(() => [ createVNode(_component_el_form_item, { label: "标题", prop: "title" }, { default: withCtx(() => [ createVNode(_component_el_input, { modelValue: formData.title, "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => formData.title = $event), placeholder: "请输入标题" }, null, 8, ["modelValue"]) ]), _: 1 }), createVNode(_component_el_form_item, { label: "内容", prop: "content" }, { default: withCtx(() => [ createVNode(_component_el_input, { modelValue: formData.content, "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => formData.content = $event), type: "textarea", rows: 6, placeholder: "请输入内容" }, null, 8, ["modelValue"]) ]), _: 1 }), createVNode(_component_el_form_item, null, { default: withCtx(() => [ createVNode(_component_el_button, { type: "primary", onClick: handleSubmit }, { default: withCtx(() => [..._cache[3] || (_cache[3] = [ createTextVNode(" 保存 ", -1) ])]), _: 1 }), createVNode(_component_el_button, { onClick: handleReset }, { default: withCtx(() => [..._cache[4] || (_cache[4] = [ createTextVNode("重置", -1) ])]), _: 1 }) ]), _: 1 }) ]), _: 1 }, 8, ["model", "rules"]) ]), _: 1 })), [ [_directive_loading, loading.value] ]) ]); }; } }); const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-8ffbc785"]]); export { index as default };