2023-12-04 19:10:26 +08:00
|
|
|
<template>
|
2023-12-12 17:54:52 +08:00
|
|
|
<el-dialog v-model.trim="addShow" :title="title" width="620px" draggable :close-on-click-modal="false">
|
|
|
|
|
<el-form :model="form" ref="ruleFormRef" label-width="88px" :rules="formRules" style="padding: 0 0px 0px 0;">
|
|
|
|
|
<el-form-item label="标题:" prop="carName">
|
|
|
|
|
<el-input v-model.trim="form.carName" placeholder="请输入标题" clearable maxlength="30" />
|
2023-12-04 19:10:26 +08:00
|
|
|
</el-form-item>
|
2023-12-12 17:54:52 +08:00
|
|
|
<el-form-item label="图片:" prop="carUrl">
|
|
|
|
|
<uploadCom :maxLimit="1" listType="picture-card" :acceptTypeList="['.jpg', '.jpeg', '.png']" width="120px"
|
|
|
|
|
height="120px" :autoUpload="true" :successResultCallBack="successResultCallBackFn" :fileList="fileList">
|
|
|
|
|
<template v-slot:default>
|
|
|
|
|
<el-icon size="48" color="#aaa">
|
|
|
|
|
<Plus />
|
|
|
|
|
</el-icon>
|
|
|
|
|
</template>
|
|
|
|
|
</uploadCom>
|
2023-12-05 20:12:35 +08:00
|
|
|
|
2023-12-04 19:10:26 +08:00
|
|
|
</el-form-item>
|
2023-12-12 17:54:52 +08:00
|
|
|
<el-form-item label="跳转链接:" prop="openUrl">
|
|
|
|
|
<el-input v-model.trim="form.openUrl" clearable />
|
2023-12-04 19:10:26 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
</el-form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<span class="dialog-footer">
|
|
|
|
|
<el-button @click="cancelFn">取消</el-button>
|
|
|
|
|
<el-button type="primary" @click="publishFn">
|
|
|
|
|
发布
|
|
|
|
|
</el-button>
|
|
|
|
|
</span>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import uploadCom from "components/com/uploadCom.vue"
|
|
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
|
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
|
import { linkReg } from "utils/reg"
|
2023-12-12 17:54:52 +08:00
|
|
|
import { apiBmCarouselSetsById, apiBmCarouselSetsAddorupdate } from "http/api/config"
|
2023-12-04 19:10:26 +08:00
|
|
|
const emits = defineEmits(['send'])
|
|
|
|
|
const addShow = ref(false)
|
2023-12-12 17:54:52 +08:00
|
|
|
let title: any = ref("新增")
|
2023-12-04 19:10:26 +08:00
|
|
|
const ruleFormRef: any = ref()
|
|
|
|
|
const form = reactive({
|
2023-12-12 17:54:52 +08:00
|
|
|
carName: '',
|
|
|
|
|
carUrl: '',
|
|
|
|
|
openUrl: '',
|
|
|
|
|
id: ''
|
2023-12-04 19:10:26 +08:00
|
|
|
})
|
2023-12-12 17:54:52 +08:00
|
|
|
|
|
|
|
|
const fileList: any = ref([])
|
2023-12-04 19:10:26 +08:00
|
|
|
// const validatorLink = (rule: any, value: any, callback: any) => {
|
|
|
|
|
// if (linkReg.test(value)) {
|
|
|
|
|
// callback()
|
|
|
|
|
// } else {
|
|
|
|
|
// callback(new Error("请输入正确格式的跳转链接"))
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
const formRules = reactive<FormRules<any>>({
|
2023-12-12 17:54:52 +08:00
|
|
|
carName: [
|
2023-12-04 19:10:26 +08:00
|
|
|
{ required: true, message: '请输入标题', trigger: 'blur' },
|
|
|
|
|
],
|
2023-12-12 17:54:52 +08:00
|
|
|
carUrl: [
|
2023-12-04 19:10:26 +08:00
|
|
|
{ required: true, message: '请上传图片', trigger: 'blur' },
|
|
|
|
|
],
|
2023-12-12 17:54:52 +08:00
|
|
|
// openUrl: [
|
2023-12-04 19:10:26 +08:00
|
|
|
// {
|
|
|
|
|
// required: true,
|
|
|
|
|
// message: '请输入跳转链接',
|
|
|
|
|
// trigger: 'blur',
|
|
|
|
|
// },
|
|
|
|
|
// {
|
|
|
|
|
// validator: validatorLink,
|
|
|
|
|
// trigger: 'blur'
|
|
|
|
|
// }
|
|
|
|
|
// ],
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const publishFn = () => {
|
|
|
|
|
if (!ruleFormRef) return
|
|
|
|
|
ruleFormRef.value.validate((valid: any) => {
|
|
|
|
|
if (valid) {
|
2023-12-12 17:54:52 +08:00
|
|
|
if (form.openUrl && !linkReg.test(form.openUrl)) {
|
2023-12-04 19:10:26 +08:00
|
|
|
ElMessage({
|
2023-12-12 17:54:52 +08:00
|
|
|
type: 'warning',
|
|
|
|
|
message: "请输入正确格式的跳转链接"
|
2023-12-04 19:10:26 +08:00
|
|
|
})
|
2023-12-12 17:54:52 +08:00
|
|
|
} else {
|
|
|
|
|
updateFn()
|
2023-12-04 19:10:26 +08:00
|
|
|
}
|
|
|
|
|
console.log('submit!')
|
|
|
|
|
} else {
|
|
|
|
|
console.log('error submit!')
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const cancelFn = (formEl: FormInstance | undefined) => {
|
|
|
|
|
if (!ruleFormRef) return
|
|
|
|
|
ruleFormRef.value.resetFields()
|
2023-12-12 17:54:52 +08:00
|
|
|
fileList.value = []
|
|
|
|
|
addShow.value = false
|
2023-12-04 19:10:26 +08:00
|
|
|
}
|
|
|
|
|
|
2023-12-12 17:54:52 +08:00
|
|
|
const open = (val: any) => {
|
2023-12-04 19:10:26 +08:00
|
|
|
title.value = "新增"
|
|
|
|
|
addShow.value = true
|
2023-12-12 17:54:52 +08:00
|
|
|
}
|
2023-12-04 19:10:26 +08:00
|
|
|
|
2023-12-12 17:54:52 +08:00
|
|
|
const edit = (id: any) => {
|
2023-12-04 19:10:26 +08:00
|
|
|
title.value = "编辑"
|
|
|
|
|
addShow.value = true
|
2023-12-12 17:54:52 +08:00
|
|
|
form.id = id
|
|
|
|
|
initApiBmCarouselSetsById(id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const initApiBmCarouselSetsById = async (id: any) => {
|
|
|
|
|
const res: any = await apiBmCarouselSetsById(id)
|
|
|
|
|
Object.assign(form, res.data)
|
|
|
|
|
const fileItem = {
|
|
|
|
|
url: res.data.carUrl,
|
|
|
|
|
name: ""
|
|
|
|
|
}
|
|
|
|
|
fileList.value = [fileItem]
|
|
|
|
|
// console.log("res-apiBmCarouselSetsById22222", fileList.value)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
const successResultCallBackFn = (val: any) => {
|
|
|
|
|
console.log("successResultCallBackFnval", val)
|
|
|
|
|
form.carUrl = val.msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const updateFn = async () => {
|
|
|
|
|
let params = Object.assign({}, form)
|
|
|
|
|
const res = await apiBmCarouselSetsAddorupdate(params)
|
|
|
|
|
console.log("apiBmCarouselSetsAddorupdate", res)
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: title.value + '成功'
|
|
|
|
|
})
|
|
|
|
|
addShow.value = false
|
2023-12-04 19:10:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
|
open,
|
|
|
|
|
edit
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss"></style>
|