数通互联化工云平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

289 lines
9.8 KiB

<!--
@ 作者: 秦东
@ 时间: 2023-07-14 08:51:25
@ 备注: 表单子表
-->
9 months ago
<script lang="ts" setup>
import FormItem from "./formItem.vue";
import { inject, computed } from "vue";
import Tooltips from "@/components/DesignForm/tooltip.vue";
import { constFormProps } from "@/api/DesignForm/utils";
import { jsonParseStringify } from "@/utils/DesignForm";
import LowcodeImagePage from "@/components/DesignForm/public/expand/lowcodeImage.vue";
import AssociatedForms from "@/widget/associatedforms/index.vue";
import UploadPageList from "@/components/DesignForm/public/expand/uploadPageList.vue";
9 months ago
import LokOrgCentent from "@/widget/org/cont.vue";
import { SCOPE } from "element-plus";
const props = withDefaults(
9 months ago
defineProps<{
data: any;
}>(),
{
data: () => {
return {};
},
}
);
const sunTableName = computed(() => {
return props.data.item ? (props.data.item.label ? props.data.item.label : "") : "";
});
const formProps = inject(constFormProps, {}) as any;
const tableDataNew = computed(() => {
9 months ago
// console.log("如果编辑页禁用时-----1---->",props.data.name)
// console.log("如果编辑页禁用时-----2---->",formProps.value.model[props.data.name])
// console.log("如果编辑页禁用时-----3---->",formProps.value.model)
// console.log("如果编辑页禁用时-----4---->",formProps.value)
return formProps.value.model[props.data.name];
});
const type = computed(() => {
9 months ago
return formProps.value.type;
});
// 如果编辑页禁用时,则返回true
const editDisabled = computed(() => {
9 months ago
return formProps.value.type === 2 && props.data.config?.editDisabled;
});
const addColumn = () => {
// console.log("如果编辑页禁用时--------->", tableDataNew.value);
9 months ago
const temp: any = {};
if (props.data.list) {
props.data.list.forEach((item: any) => {
if (item.name) {
temp[item.name] = item.control.modelValue;
}
});
// console.log("如果编辑页禁用时-------temp:", temp);
// console.log("如果编辑页禁用时-------jsonParseStringify:", jsonParseStringify(temp));
9 months ago
tableDataNew.value.push(jsonParseStringify(temp));
}
};
const getText = (text: any, val: any, name: any) => {
// console.log("text===>", text);
// console.log("name===>", name);
// console.log("val===>", val);
9 months ago
if (typeof text === "string") {
return text;
} else {
return text && text.toString();
}
};
const delColumn = (index: number) => {
9 months ago
tableDataNew.value.splice(index, 1);
};
/**
@ 作者: 秦东
@ 时间: 2024-08-02 13:22:14
@ 功能: 时间戳转换对象
*/
9 months ago
const timeToAry = (timestamp: number) => {
const date = new Date(timestamp);
const year = date.getFullYear();
const month = ("0" + (date.getMonth() + 1)).slice(-2);
const day = ("0" + date.getDate()).slice(-2);
const hours = ("0" + date.getHours()).slice(-2);
const minutes = ("0" + date.getMinutes()).slice(-2);
const seconds = ("0" + date.getSeconds()).slice(-2);
return {
year: year,
month: month,
day: day,
hours: hours,
minutes: minutes,
seconds,
};
};
/**
@ 作者: 秦东
@ 时间: 2024-08-02 13:02:49
@ 功能: 将时间戳转换成字符串
*/
9 months ago
const timeToString = (timeVal: any, types: int) => {
let timeStr = "";
if (Array.isArray(timeVal)) {
if (timeVal.length >= 2) {
let startTime = timeToAry(timeVal[0]);
let endTime = timeToAry(timeVal[1]);
switch (types) {
case "year": //年
timeStr = `${startTime.year}${endTime.year}`;
break;
case "month": //月
timeStr = `${startTime.year}-${startTime.month}${endTime.year}-${endTime.month}`;
break;
case "datetime": //日期+时间
timeStr = `${startTime.year}-${startTime.month}-${startTime.day} ${startTime.hours}:${startTime.minutes}:${startTime.seconds}${endTime.year}-${endTime.month}-${endTime.day} ${endTime.hours}:${endTime.minutes}:${endTime.seconds}`;
break;
case "week": //周
let startWeek = getYearWeek(startTime);
let endWeek = getYearWeek(endTime);
timeStr = `${startWeek}${endWeek}`;
break;
case "timeCalss": //时间
timeStr = `${startTime.hours}:${startTime.minutes}:${startTime.seconds}${endTime.hours}:${endTime.minutes}:${endTime.seconds}`;
break;
case "datetimerange":
timeStr = `${startTime.year}-${startTime.month}-${startTime.day} ${startTime.hours}:${startTime.minutes}:${startTime.seconds}${endTime.year}-${endTime.month}-${endTime.day} ${endTime.hours}:${endTime.minutes}:${endTime.seconds}`;
break;
case "daterange":
timeStr = `${startTime.year}-${startTime.month}-${startTime.day}${endTime.year}-${endTime.month}-${endTime.day}`;
break;
case "monthrange":
timeStr = `${startTime.year}-${startTime.month}${endTime.year}-${endTime.month}`;
break;
default:
timeStr = `${startTime.year}-${startTime.month}-${startTime.day}${endTime.year}-${endTime.month}-${endTime.day}`;
break;
}
} else if (timeVal.length == 1) {
let { year, month, day, hours, minutes, seconds } = timeToAry(timeVal[0]);
switch (types) {
case "year": //年
timeStr = `${year}`;
break;
case "month": //月
timeStr = `${year}-${month}`;
break;
case "datetime": //日期+时间
timeStr = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
break;
case "week": //周
timeStr = getYearWeek(timeVal);
break;
case "timeCalss": //时间
timeStr = `${hours}:${minutes}:${seconds}`;
break;
default:
timeStr = `${year}-${month}-${day}`;
break;
}
} else {
timeStr = "未知时间";
}
} else {
let { year, month, day, hours, minutes, seconds } = timeToAry(timeVal);
switch (types) {
case "year": //年
timeStr = `${year}`;
break;
case "month": //月
timeStr = `${year}-${month}`;
break;
case "datetime": //日期+时间
timeStr = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
break;
case "week": //周
timeStr = getYearWeek(timeVal);
break;
case "timeCalss": //时间
timeStr = `${hours}:${minutes}:${seconds}`;
break;
default:
timeStr = `${year}-${month}-${day}`;
break;
}
}
return timeStr;
};
let associatedFormsIndexTablekey = 0;
/* const emits = defineEmits<{
(e: 'asfValueChanged', val: any): void
}>() */
9 months ago
let emits = defineEmits(["optionsValue3GetTable", "asfValueChanged"]);
9 months ago
function asfValueChanged(val: any) {
//console.log("childTable-asfValueChanged",val)
emits("asfValueChanged", val);
}
9 months ago
function optionsValue3Get1(data: any, fieldName: string) {
fieldName = "childTable---" + props.data.name + "---" + fieldName;
/* console.log("childTable---optionsValue3Get1")
console.log(props.data.name) */
9 months ago
emits("optionsValue3GetTable", data, fieldName);
}
</script>
<template>
9 months ago
<div class="form-table form-table-add">
<el-text class="mx-1" size="large">{{ sunTableName }}</el-text>
<el-table v-bind="data.control" :class="[data.className]" :data="tableDataNew">
<el-table-column
v-for="(item, index) in data.list"
:key="index"
:prop="item.name"
:label="item.item.label"
:width="item.item.span"
>
<template #default="scope">
<span v-if="item.type === 'index'">{{ scope.$index + 1 }}</span>
<div v-if="type === 4 || editDisabled">
<LokOrgCentent
v-if="item.type == 'orgCentent'"
:orgid="scope.row[item.name].toString()"
/>
<div v-else-if="item.type == 'lowcodeImage'">
<LowcodeImagePage :data="item" v-model="scope.row[item.name]" />
</div>
<div v-else-if="item.type == 'upload'">
<UploadPageList
:data="item"
:img-list="scope.row[item.name]"
:control="item.control"
/>
</div>
<div
v-else-if="item.type == 'datePicker'"
v-html="timeToString(scope.row[item.name], item.control.type)"
></div>
<div v-else-if="item.type == 'associatedForms'">
<AssociatedForms
:data="item"
v-model="scope.row[item.name]"
:tablekey="associatedFormsIndexTablekey"
:row-index="scope.$index"
/>
</div>
<div v-else>{{ getText(scope.row[item.name], scope.row, item.name) }}</div>
</div>
<div v-else>
<form-item
v-model="scope.row[item.name]"
:tProp="`${data.name}.${scope.$index}.${item.name}`"
:row-index="scope.$index"
:data="item"
@asf-value-changed="asfValueChanged"
@optionsValue3Get1="optionsValue3Get1"
/>
</div>
</template>
<template #header="scope" v-if="item.help">
{{ scope.column.label }}
<Tooltip :content="item.help" />
</template>
</el-table-column>
<el-table-column
prop="del"
label="操作"
v-if="[1, 2].includes(type as number) && data.config.delBtnText && !editDisabled"
>
<template #default="scope">
<el-button link type="primary" @click="delColumn(scope.$index)">{{
data.config.delBtnText
}}</el-button>
</template>
</el-table-column>
</el-table>
<div
class="table-btn"
v-if="[1, 2].includes(type as number) && data.config.addBtnText && !editDisabled"
>
<el-button size="small" @click="addColumn">{{ data.config.addBtnText }}</el-button>
</div>
</div>
</template>
9 months ago
<style lang="scss" scoped></style>