refactor: 所有业务线的接口调用添加TypeScript类型声明描述

This commit is contained in:
郝先瑞
2022-03-13 22:22:08 +08:00
parent 65035f584e
commit f2ca77992c
36 changed files with 1558 additions and 1214 deletions

View File

@@ -2,131 +2,148 @@
<div class="component-container">
<div class="component-container__main">
<el-form
ref="dataFormRef"
:rules="rules"
:model="modelValue"
label-width="120px"
ref="dataFormRef"
:rules="rules"
:model="modelValue"
label-width="120px"
>
<el-form-item label="商品品牌" prop="brandId">
<el-select
v-model="modelValue.brandId"
style="width:400px"
clearable
v-model="modelValue.brandId"
style="width: 400px"
clearable
>
<el-option
v-for="item in brandOptions"
:key="item.id"
:label="item.name"
:value="item.id"
v-for="item in brandOptions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="商品名称" prop="name">
<el-input style="width: 400px" v-model="modelValue.name"/>
<el-input style="width: 400px" v-model="modelValue.name" />
</el-form-item>
<el-form-item label="原价" prop="originPrice">
<el-input style="width: 400px" v-model="modelValue.originPrice"/>
<el-input style="width: 400px" v-model="modelValue.originPrice" />
</el-form-item>
<el-form-item label="现价" prop="price">
<el-input style="width: 400px" v-model="modelValue.price"/>
<el-input style="width: 400px" v-model="modelValue.price" />
</el-form-item>
<el-form-item label="商品简介">
<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 6 }" v-model="modelValue.description"/>
<el-input
type="textarea"
:autosize="{ minRows: 3, maxRows: 6 }"
v-model="modelValue.description"
/>
</el-form-item>
<el-form-item label="商品相册">
<el-card v-for="(item,index) in pictures" style="width: 170px;display: inline-block;margin-left: 10px"
:body-style="{ padding: '10px' }">
<el-card
v-for="(item, index) in pictures"
:key="index"
style="width: 170px; display: inline-block; margin-left: 10px;text-align:center"
:body-style="{ padding: '10px' }"
>
<single-upload v-model="item.url" :show-close="true" />
<single-upload v-model="item.url"/>
<div class="bottom" v-if="item.url">
<el-button type="text" class="button" v-if="item.main==true" style="color:#ff4d51">商品主图</el-button>
<el-button type="text" class="button" v-else @click="changeMainPicture(index)">设为主图</el-button>
<el-button type="text" class="button" @click="removePicture(index)">删除图片</el-button>
<div v-if="item.url">
<el-button
type="text"
class="button"
v-if="item.main == true"
style="color: #ff4d51"
>商品主图</el-button
>
<el-button
type="text"
class="button"
v-else
@click="changeMainPicture(index)"
>设为主图</el-button
>
</div>
<div class="bottom" v-else>
<div v-else>
<!-- 占位 -->
<el-button type="text"/>
<el-button type="text" />
</div>
</el-card>
</el-form-item>
<el-form-item label="商品详情" prop="detail">
<editor v-model="modelValue.detail" style="height: 600px"/>
<editor v-model="modelValue.detail" style="height: 600px" />
</el-form-item>
</el-form>
</div>
<div class="component-container__footer">
<el-button @click="handlePrev">上一步选择商品分类</el-button>
<el-button type="primary" @click="handleNext">下一步设置商品属性</el-button>
<el-button type="primary" @click="handleNext"
>下一步设置商品属性</el-button
>
</div>
</div>
</template>
<script setup lang="ts">
import {onMounted, reactive, ref, toRefs, unref} from "vue"
import {ElForm} from "element-plus"
import { onMounted, reactive, ref, toRefs } from "vue";
import { ElForm } from "element-plus";
// API 依赖
import {listBrands} from "@/api/pms/brand"
import { listBrands } from "@/api/pms/brand";
// 自定义组件依赖
import SingleUpload from '@/components/Upload/SingleUpload.vue'
import Editor from '@/components/WangEditor/index.vue'
import Editor from "@/components/WangEditor/index.vue";
import SingleUpload from "@/components/Upload/SingleUpload.vue";
const emit = defineEmits(['prev', 'next'])
const dataFormRef = ref(ElForm)
const emit = defineEmits(["prev", "next"]);
const dataFormRef = ref(ElForm);
const props = defineProps({
modelValue: {
type: Object,
default: {}
}
})
default: {},
},
});
const state = reactive({
brandOptions: [] as Array<any>,
// 商品图册
pictures: [
{url: undefined, main: true}, // main = true 代表主图,可切换
{url: undefined, main: false},
{url: undefined, main: false},
{url: undefined, main: false},
{url: undefined, main: false}
{ url: undefined, main: true }, // main = true 代表主图,可切换
{ url: undefined, main: false },
{ url: undefined, main: false },
{ url: undefined, main: false },
{ url: undefined, main: false },
] as Array<any>,
rules: {
name: [{required: true, message: '请填写商品名称', trigger: 'blur'}],
originPrice: [{required: true, message: '请填写原价', trigger: 'blur'}],
price: [{required: true, message: '请填写现价', trigger: 'blur'}],
brandId: [{required: true, message: '请选择商品品牌', trigger: 'blur'}],
}
})
name: [{ required: true, message: "请填写商品名称", trigger: "blur" }],
originPrice: [{ required: true, message: "请填写原价", trigger: "blur" }],
price: [{ required: true, message: "请填写现价", trigger: "blur" }],
brandId: [{ required: true, message: "请选择商品品牌", trigger: "blur" }],
},
});
const {brandOptions, pictures, rules} = toRefs(state)
const { brandOptions, pictures, rules } = toRefs(state);
function loadData() {
listBrands({}).then(response => {
state.brandOptions = response.data
})
const goodsInfo = props.modelValue
console.log('商品信息', goodsInfo)
const goodsId = goodsInfo.id
listBrands().then(({data}) => {
state.brandOptions = data;
});
const goodsInfo = props.modelValue;
const goodsId = goodsInfo.id;
if (goodsId) {
const mainPicUrl = goodsInfo.picUrl
const mainPicUrl = goodsInfo.picUrl;
if (mainPicUrl) {
state.pictures.filter(item => item.main)[0].url = mainPicUrl
state.pictures.filter((item) => item.main)[0].url = mainPicUrl;
}
const subPicUrls = goodsInfo.subPicUrls
const subPicUrls = goodsInfo.subPicUrls;
if (subPicUrls && subPicUrls.length > 0) {
for (let i = 1; i <= subPicUrls.length; i++) {
state.pictures[i].url = subPicUrls[i - 1]
state.pictures[i].url = subPicUrls[i - 1];
}
}
}
@@ -134,63 +151,65 @@ function loadData() {
function resetForm() {
state.pictures = [
{url: undefined, main: true}, // main 代表主图,可以切换
{url: undefined, main: false},
{url: undefined, main: false},
{url: undefined, main: false},
{url: undefined, main: false}
]
{ url: undefined, main: true }, // main 代表主图,可以切换
{ url: undefined, main: false },
{ url: undefined, main: false },
{ url: undefined, main: false },
{ url: undefined, main: false },
];
}
/**
* 切换主图
*/
function changeMainPicture(changeIndex: number) {
const currMainPicture = JSON.parse(JSON.stringify(state.pictures[0]))
const nextMainPicture = JSON.parse(JSON.stringify(state.pictures[changeIndex]))
const currMainPicture = JSON.parse(JSON.stringify(state.pictures[0]));
const nextMainPicture = JSON.parse(
JSON.stringify(state.pictures[changeIndex])
);
state.pictures[0].url = nextMainPicture.url
state.pictures[changeIndex].url = currMainPicture.url
}
function removePicture(index: number) {
state.pictures[index].url = undefined
state.pictures[0].url = nextMainPicture.url;
state.pictures[changeIndex].url = currMainPicture.url;
}
function handlePrev() {
emit('prev')
emit("prev");
}
function handleNext() {
dataFormRef.value.validate((valid: any) => {
if (valid) {
// 商品图片
const mainPicUrl = state.pictures.filter(item => item.main == true && item.url).map(item => item.url)
const mainPicUrl = state.pictures
.filter((item) => item.main == true && item.url)
.map((item) => item.url);
if (mainPicUrl && mainPicUrl.length > 0) {
props.modelValue.picUrl = mainPicUrl[0]
props.modelValue.picUrl = mainPicUrl[0];
}
const subPicUrl = state.pictures.filter(item => item.main == false && item.url).map(item => item.url)
const subPicUrl = state.pictures
.filter((item) => item.main == false && item.url)
.map((item) => item.url);
if (subPicUrl && subPicUrl.length > 0) {
props.modelValue.subPicUrls = subPicUrl
props.modelValue.subPicUrls = subPicUrl;
}
emit('next')
emit("next");
}
})
});
}
onMounted(() => {
loadData()
})
loadData();
});
</script>
<style lang="scss" scoped>
.component-container {
&__main {
margin: 20px auto;
.button {
margin-left: 10px;
}
}
@@ -198,6 +217,7 @@ onMounted(() => {
position: fixed;
bottom: 20px;
right: 20px;
}
}
</style>