refactor: ♻️ 重构API为静态方法实现模块化管理,并将types.ts重命名为model.ts用于存放接口模型定义
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { getDictOptions } from "@/api/dict";
|
||||
import DictAPI from "@/api/dict";
|
||||
|
||||
const props = defineProps({
|
||||
/**
|
||||
@@ -66,8 +66,8 @@ function handleChange(val?: string | number | undefined) {
|
||||
|
||||
onBeforeMount(() => {
|
||||
// 根据字典类型编码(typeCode)获取字典选项
|
||||
getDictOptions(props.typeCode).then((response) => {
|
||||
options.value = response.data;
|
||||
DictAPI.getDictOptions(props.typeCode).then((data) => {
|
||||
options.value = data;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -265,7 +265,7 @@ function fetchPageData(formData: IObject = {}, isRestart = false) {
|
||||
}
|
||||
props.contentConfig
|
||||
.indexAction({ ...queryParams, ...formData })
|
||||
.then(({ data }) => {
|
||||
.then((data) => {
|
||||
total.value = data.total;
|
||||
pageData.value = data.list;
|
||||
})
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
<!--
|
||||
多图上传组件
|
||||
@author: youlaitech
|
||||
@date 2022/11/20
|
||||
-->
|
||||
|
||||
<!-- 多图上传组件 -->
|
||||
<template>
|
||||
<el-upload
|
||||
v-model:file-list="fileList"
|
||||
@@ -30,7 +25,7 @@ import {
|
||||
UploadFile,
|
||||
UploadProps,
|
||||
} from "element-plus";
|
||||
import { uploadFileApi, deleteFileApi } from "@/api/file";
|
||||
import FileAPI from "@/api/file";
|
||||
|
||||
const emit = defineEmits(["update:modelValue"]);
|
||||
|
||||
@@ -83,7 +78,7 @@ watch(
|
||||
*/
|
||||
async function handleUpload(options: UploadRequestOptions): Promise<any> {
|
||||
// 上传API调用
|
||||
const { data: fileInfo } = await uploadFileApi(options.file);
|
||||
const { data: fileInfo } = await FileAPI.upload(options.file);
|
||||
|
||||
// 上传成功需手动替换文件路径为远程URL,否则图片地址为预览地址 blob:http://
|
||||
const fileIndex = fileList.value.findIndex(
|
||||
@@ -108,7 +103,7 @@ function handleRemove(removeFile: UploadFile) {
|
||||
const filePath = removeFile.url;
|
||||
|
||||
if (filePath) {
|
||||
deleteFileApi(filePath).then(() => {
|
||||
FileAPI.deleteByPath(filePath).then(() => {
|
||||
// 删除成功回调
|
||||
emit(
|
||||
"update:modelValue",
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { UploadRawFile, UploadRequestOptions } from "element-plus";
|
||||
import { uploadFileApi } from "@/api/file";
|
||||
import FileAPI from "@/api/file";
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
@@ -33,7 +33,7 @@ const imgUrl = useVModel(props, "modelValue", emit);
|
||||
* @param options
|
||||
*/
|
||||
async function uploadFile(options: UploadRequestOptions): Promise<any> {
|
||||
const { data: fileInfo } = await uploadFileApi(options.file);
|
||||
const { data: fileInfo } = await FileAPI.update(options.file);
|
||||
imgUrl.value = fileInfo.url;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user