refactor(src): 优化代码格式和功能
- 调整了部分组件中的代码格式,提高了可读性 - 优化了图像上传功能,增加了对高度的处理逻辑 - 移除了不必要的注释代码 - 统一了异步函数的定义方式
This commit is contained in:
@@ -107,7 +107,14 @@ const functions = {
|
||||
// max-width:${maxWidth}px;
|
||||
// max-height:${maxHeight}px"`;
|
||||
// 使用原始高度
|
||||
const height = img.naturalHeight;
|
||||
const minimum = 50;
|
||||
let height = img.naturalHeight;
|
||||
const scale = img.naturalHeight / 50;
|
||||
if (height > minimum * 3) {
|
||||
height = height / scale;
|
||||
} else {
|
||||
height = minimum;
|
||||
}
|
||||
// 根据宽高比计算宽度
|
||||
const width = (height * 3) / 4;
|
||||
const maxWidth = img.naturalWidth;
|
||||
|
||||
@@ -313,7 +313,7 @@ const actionEvent = (item, el) => {
|
||||
};
|
||||
// 总事件注册
|
||||
const actionFun = {
|
||||
// 单选事件 添加选项
|
||||
// 单选事件 添加选项 无限制添加
|
||||
radioAddOption: (element) => {
|
||||
element.options.map((item) => {
|
||||
item.push({
|
||||
|
||||
@@ -82,22 +82,22 @@
|
||||
</van-field>
|
||||
|
||||
<van-divider></van-divider>
|
||||
<van-field label="文件格式" :border="false" label-align="top">
|
||||
<template #input>
|
||||
<div style="width: 100%">
|
||||
<YLCascader
|
||||
v-if="fileTypeList.length > 0"
|
||||
v-model="fileType"
|
||||
:options="fileTypeList"
|
||||
@update:model-value="changeFileType"
|
||||
></YLCascader>
|
||||
</div>
|
||||
</template>
|
||||
</van-field>
|
||||
<!-- <van-field label="文件格式" :border="false" label-align="top">-->
|
||||
<!-- <template #input>-->
|
||||
<!-- <div style="width: 100%">-->
|
||||
<!-- <YLCascader-->
|
||||
<!-- v-if="fileTypeList.length > 0"-->
|
||||
<!-- v-model="fileType"-->
|
||||
<!-- :options="fileTypeList"-->
|
||||
<!-- @update:model-value="changeFileType"-->
|
||||
<!-- ></YLCascader>-->
|
||||
<!-- </div>-->
|
||||
<!-- </template>-->
|
||||
<!-- </van-field>-->
|
||||
</template>
|
||||
<script setup>
|
||||
import { computed, defineEmits, onMounted, ref } from 'vue';
|
||||
import YLCascader from '@/components/YLCascader.vue';
|
||||
// import YLCascader from '@/components/YLCascader.vue';
|
||||
|
||||
import { getFileType } from './Api/Index.js';
|
||||
const props = defineProps({
|
||||
@@ -151,23 +151,23 @@ const getFileTypeList = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const changeFileType = (value) => {
|
||||
if (value === [['0']]) {
|
||||
actionQuestion.value.config.file_type = '0';
|
||||
emit('saveOption');
|
||||
return;
|
||||
}
|
||||
const ls = [];
|
||||
value.map((item) => {
|
||||
const obj = [];
|
||||
item.map((s) => {
|
||||
obj.push(s);
|
||||
});
|
||||
ls.push(obj.join('-'));
|
||||
});
|
||||
actionQuestion.value.config.file_type = ls.join(',');
|
||||
emit('saveOption');
|
||||
};
|
||||
// const changeFileType = (value) => {
|
||||
// if (value === [['0']]) {
|
||||
// actionQuestion.value.config.file_type = '0';
|
||||
// emit('saveOption');
|
||||
// return;
|
||||
// }
|
||||
// const ls = [];
|
||||
// value.map((item) => {
|
||||
// const obj = [];
|
||||
// item.map((s) => {
|
||||
// obj.push(s);
|
||||
// });
|
||||
// ls.push(obj.join('-'));
|
||||
// });
|
||||
// actionQuestion.value.config.file_type = ls.join(',');
|
||||
// emit('saveOption');
|
||||
// };
|
||||
onMounted(() => {
|
||||
getFileTypeList();
|
||||
});
|
||||
|
||||
@@ -84,6 +84,9 @@ const element = defineModel('element', {
|
||||
return {};
|
||||
}
|
||||
});
|
||||
// if (props.index + 1 !== Number(element.value.title)) {
|
||||
// element.value.title = props.index + 1;
|
||||
// }
|
||||
|
||||
// 选中题目后出现的操作
|
||||
const emit = defineEmits(['getChooseQuestionId', 'move', 'copy', 'setting', 'logics']);
|
||||
|
||||
@@ -141,7 +141,7 @@ const onLoad = () => {
|
||||
fetchSurveys();
|
||||
}, 500);
|
||||
};
|
||||
const fetchSurveys = async () => {
|
||||
const fetchSurveys = async() => {
|
||||
const params = {
|
||||
page: form.value.page,
|
||||
per_page: form.value.pageSize,
|
||||
@@ -179,7 +179,7 @@ const deleteItem = (item) => {
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#03B03C'
|
||||
})
|
||||
.then(async () => {
|
||||
.then(async() => {
|
||||
const res = await deleteSurveys(item.sn);
|
||||
if (res.data.message) {
|
||||
showToast(res.data.message);
|
||||
@@ -203,7 +203,7 @@ const copyItem = (item) => {
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#03B03C'
|
||||
})
|
||||
.then(async () => {
|
||||
.then(async() => {
|
||||
const res = await copySurveys(item.sn);
|
||||
if (res.data.code === 200 || res.data.code === 201) {
|
||||
showSuccessToast('复制成功');
|
||||
@@ -262,7 +262,7 @@ const editItem = (item) => {
|
||||
});
|
||||
};
|
||||
// 保存为模板
|
||||
const saveTemplate = async (item) => {
|
||||
const saveTemplate = async(item) => {
|
||||
const data = JSON.parse(JSON.stringify(item));
|
||||
const res = await saveTemplates(item.sn, data);
|
||||
if (res.data.code === 200 || res.data.code === 201) {
|
||||
|
||||
Reference in New Issue
Block a user