refactor(src): 优化代码格式和功能

- 调整了部分组件中的代码格式,提高了可读性
- 优化了图像上传功能,增加了对高度的处理逻辑
- 移除了不必要的注释代码
- 统一了异步函数的定义方式
This commit is contained in:
陈昱达
2025-03-20 17:15:29 +08:00
parent 70e0ebda62
commit 0952a2f523
5 changed files with 46 additions and 36 deletions

View File

@@ -107,7 +107,14 @@ const functions = {
// max-width:${maxWidth}px; // max-width:${maxWidth}px;
// max-height:${maxHeight}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 width = (height * 3) / 4;
const maxWidth = img.naturalWidth; const maxWidth = img.naturalWidth;

View File

@@ -313,7 +313,7 @@ const actionEvent = (item, el) => {
}; };
// 总事件注册 // 总事件注册
const actionFun = { const actionFun = {
// 单选事件 添加选项 // 单选事件 添加选项 无限制添加
radioAddOption: (element) => { radioAddOption: (element) => {
element.options.map((item) => { element.options.map((item) => {
item.push({ item.push({

View File

@@ -82,22 +82,22 @@
</van-field> </van-field>
<van-divider></van-divider> <van-divider></van-divider>
<van-field label="文件格式" :border="false" label-align="top"> <!-- <van-field label="文件格式" :border="false" label-align="top">-->
<template #input> <!-- <template #input>-->
<div style="width: 100%"> <!-- <div style="width: 100%">-->
<YLCascader <!-- <YLCascader-->
v-if="fileTypeList.length > 0" <!-- v-if="fileTypeList.length > 0"-->
v-model="fileType" <!-- v-model="fileType"-->
:options="fileTypeList" <!-- :options="fileTypeList"-->
@update:model-value="changeFileType" <!-- @update:model-value="changeFileType"-->
></YLCascader> <!-- ></YLCascader>-->
</div> <!-- </div>-->
</template> <!-- </template>-->
</van-field> <!-- </van-field>-->
</template> </template>
<script setup> <script setup>
import { computed, defineEmits, onMounted, ref } from 'vue'; 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'; import { getFileType } from './Api/Index.js';
const props = defineProps({ const props = defineProps({
@@ -151,23 +151,23 @@ const getFileTypeList = () => {
}); });
}; };
const changeFileType = (value) => { // const changeFileType = (value) => {
if (value === [['0']]) { // if (value === [['0']]) {
actionQuestion.value.config.file_type = '0'; // actionQuestion.value.config.file_type = '0';
emit('saveOption'); // emit('saveOption');
return; // return;
} // }
const ls = []; // const ls = [];
value.map((item) => { // value.map((item) => {
const obj = []; // const obj = [];
item.map((s) => { // item.map((s) => {
obj.push(s); // obj.push(s);
}); // });
ls.push(obj.join('-')); // ls.push(obj.join('-'));
}); // });
actionQuestion.value.config.file_type = ls.join(','); // actionQuestion.value.config.file_type = ls.join(',');
emit('saveOption'); // emit('saveOption');
}; // };
onMounted(() => { onMounted(() => {
getFileTypeList(); getFileTypeList();
}); });

View File

@@ -84,6 +84,9 @@ const element = defineModel('element', {
return {}; return {};
} }
}); });
// if (props.index + 1 !== Number(element.value.title)) {
// element.value.title = props.index + 1;
// }
// 选中题目后出现的操作 // 选中题目后出现的操作
const emit = defineEmits(['getChooseQuestionId', 'move', 'copy', 'setting', 'logics']); const emit = defineEmits(['getChooseQuestionId', 'move', 'copy', 'setting', 'logics']);

View File

@@ -141,7 +141,7 @@ const onLoad = () => {
fetchSurveys(); fetchSurveys();
}, 500); }, 500);
}; };
const fetchSurveys = async () => { const fetchSurveys = async() => {
const params = { const params = {
page: form.value.page, page: form.value.page,
per_page: form.value.pageSize, per_page: form.value.pageSize,
@@ -179,7 +179,7 @@ const deleteItem = (item) => {
showCancelButton: true, showCancelButton: true,
confirmButtonColor: '#03B03C' confirmButtonColor: '#03B03C'
}) })
.then(async () => { .then(async() => {
const res = await deleteSurveys(item.sn); const res = await deleteSurveys(item.sn);
if (res.data.message) { if (res.data.message) {
showToast(res.data.message); showToast(res.data.message);
@@ -203,7 +203,7 @@ const copyItem = (item) => {
showCancelButton: true, showCancelButton: true,
confirmButtonColor: '#03B03C' confirmButtonColor: '#03B03C'
}) })
.then(async () => { .then(async() => {
const res = await copySurveys(item.sn); const res = await copySurveys(item.sn);
if (res.data.code === 200 || res.data.code === 201) { if (res.data.code === 200 || res.data.code === 201) {
showSuccessToast('复制成功'); showSuccessToast('复制成功');
@@ -262,7 +262,7 @@ const editItem = (item) => {
}); });
}; };
// 保存为模板 // 保存为模板
const saveTemplate = async (item) => { const saveTemplate = async(item) => {
const data = JSON.parse(JSON.stringify(item)); const data = JSON.parse(JSON.stringify(item));
const res = await saveTemplates(item.sn, data); const res = await saveTemplates(item.sn, data);
if (res.data.code === 200 || res.data.code === 201) { if (res.data.code === 200 || res.data.code === 201) {