feat: 对接接口

This commit is contained in:
wangsongsole 2024-04-21 13:58:16 +08:00
parent fd8d48a285
commit dc2e79b557
1 changed files with 14 additions and 62 deletions

View File

@ -1,4 +1,4 @@
import { getDefineButtons, handelResponse, postClientPrompt } from "@/assets/api.js" import { getDefineButtons, handelResponse, updateDefineButtons } from "@/assets/api.js"
import Grid from "@/components/gird/main.js" import Grid from "@/components/gird/main.js"
import Ipt from "@/components/input/main" import Ipt from "@/components/input/main"
import TabPage from "@/components/tabPage/main.js" import TabPage from "@/components/tabPage/main.js"
@ -13,9 +13,9 @@ export default function DefineButton() {
const Column = [ const Column = [
{ {
title: "范围", title: "范围",
prop: "type", prop: "text",
name: "type", name: "text",
type: "slot", type: "normal",
width: "400px" width: "400px"
}, },
{ {
@ -27,8 +27,8 @@ export default function DefineButton() {
}, },
{ {
title: "更新文案", title: "更新文案",
prop: "updateCustomize", prop: "custom",
name: "updateCustomize", name: "custom",
type: "slot", type: "slot",
width: "auto" width: "auto"
} }
@ -36,7 +36,6 @@ export default function DefineButton() {
const [state, setState] = useSetState({ const [state, setState] = useSetState({
tableData: [], tableData: [],
backupTableData: [],
tabs: [{ title: "文案列表" }], tabs: [{ title: "文案列表" }],
planId: sessionStorage.getItem("plan_id") planId: sessionStorage.getItem("plan_id")
}) })
@ -47,8 +46,7 @@ export default function DefineButton() {
res, res,
(req, msg) => { (req, msg) => {
setState({ setState({
tableData: cloneDeep(req), tableData: cloneDeep(req)
backupTableData: cloneDeep(req)
}) })
}, },
(error) => { (error) => {
@ -58,39 +56,9 @@ export default function DefineButton() {
}) })
}, []) }, [])
/* 区分类型 */
function typeFn(va) {
switch (va) {
case 0:
return "通用"
case 1:
return "兑换码"
case 2:
return "立减金"
case 3:
return "红包"
default:
break
}
}
/* 提交 */ /* 提交 */
function submit() { function submit() {
const submitData = [] updateDefineButtons(state.planId, { button_conf: state.tableData }).then((res) => {
state.tableData.map((item) => {
state.backupTableData.map((items) => {
if (item.message_index === items.message_index && item.customize !== items.customize) {
const { message_index, uuid, customize } = item
submitData.push({
message_index,
uuid,
customize
})
}
})
})
postClientPrompt(submitData, state.planId).then((res) => {
handelResponse( handelResponse(
res, res,
(req, msg) => { (req, msg) => {
@ -117,25 +85,22 @@ export default function DefineButton() {
Column={Column} Column={Column}
maxheight={670} maxheight={670}
ComponentHandler={(com, rowData) => { ComponentHandler={(com, rowData) => {
if (com === "type") { if (com === "custom") {
return <p>{typeFn(rowData.type)}</p>
}
if (com === "updateCustomize") {
return ( return (
<Ipt <Ipt
onChange={(e) => { onChange={(e) => {
rowData.customize = e rowData.custom = e
setState({ ...state }) setState({ ...state })
}} }}
onClearItem={() => { onClearItem={() => {
rowData.customize = "" rowData.custom = ""
setState({ ...state }) setState({ ...state })
}} }}
value={rowData.customize} value={rowData.custom}
placeholder="请输入(变量使用 ${xx} 格式。)" placeholder="请输入按钮文案"
labelWidth={"0px"} labelWidth={"0px"}
countShow={false} countShow={false}
maxLength={50} maxLength={6}
disabled={rowData.readOnly} disabled={rowData.readOnly}
height={"36px"} height={"36px"}
width={"400px"} width={"400px"}
@ -143,19 +108,6 @@ export default function DefineButton() {
/> />
) )
} }
if (com === "label") {
return (
<div>
{rowData.label.length
? rowData.label.map((item) => (
<p className="variable" key={item.index}>
{item.name}: <span>{item.index}</span>
</p>
))
: "-"}
</div>
)
}
}} }}
/> />
</TabPage> </TabPage>