123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- <template>
- <div
- v-if="element.type === 'grid'"
- grid="~ cols-24"
- :style="`gap: ${element.options.gutter}px; align-items: ${element.options.align};`"
- >
- <div
- v-for="(col, colIndex) of element.columns"
- :key="colIndex"
- :style="`grid-column: span ${col.span}`"
- >
- <GenerateFormItem
- v-for="colItem of col.list"
- :key="colItem.key"
- :request="request"
- :model="model"
- :updated-model="updatedModel"
- :element="colItem"
- :config="config"
- :disabled="disabled"
- :widgetFormData="element.columns"
- @updateWidgetForm="updateWidgetForm"
- />
- </div>
- </div>
- <el-table
- v-else-if="element.type === 'table'"
- border
- class="mb-4.5"
- :data="element.options.defaultValue"
- >
- <el-table-column
- v-for="i in element.columns"
- :key="i.prop"
- :align="element.options.align"
- v-bind="i"
- />
- </el-table>
- <el-divider
- v-else-if="element.type === 'divider'"
- :data="element.options.defaultValue"
- content-position="left"
- >
- {{ element.label }}
- </el-divider>
- <el-form-item
- v-else-if="element"
- :key="element.key"
- :label="element.label"
- :prop="element.model"
- :style="
- element.type === 'download' ? 'display:inline-flex;margin-right:40px' : ''
- "
- :label-width="element.labelWidth"
- >
- <template v-if="element.type === 'input'">
- <el-input
- v-model.trim="data"
- :style="{ width: element.options.width }"
- :placeholder="element.options.placeholder"
- :maxlength="parseInt(element.options.maxlength)"
- :clearable="element.options.clearable"
- :readonly="element.options.readonly"
- :disabled="disabled || element.options.disabled"
- >
- <template v-if="element.options.prefix" #prefix>
- {{
- element.options.prefix
- }}
- </template>
- <template v-if="element.options.suffix" #suffix>
- {{
- element.options.suffix
- }}
- </template>
- <template v-if="element.options.prepend" #prepend>
- {{
- element.options.prepend
- }}
- </template>
- <template v-if="element.options.append" #append>
- {{
- element.options.append
- }}
- </template>
- </el-input>
- </template>
- <template v-if="element.type === 'password'">
- <el-input
- v-model.trim="data"
- :style="{ width: element.options.width }"
- :placeholder="element.options.placeholder"
- :maxlength="parseInt(element.options.maxlength)"
- :clearable="element.options.clearable"
- :disabled="disabled || element.options.disabled"
- :readonly="element.options.readonly"
- :show-password="element.options.showPassword"
- >
- <template v-if="element.options.prefix" #prefix>
- {{
- element.options.prefix
- }}
- </template>
- <template v-if="element.options.suffix" #suffix>
- {{
- element.options.suffix
- }}
- </template>
- <template v-if="element.options.prepend" #prepend>
- {{
- element.options.prepend
- }}
- </template>
- <template v-if="element.options.append" #append>
- {{
- element.options.append
- }}
- </template>
- </el-input>
- </template>
- <template v-if="element.type === 'textarea'">
- <el-input
- v-model.trim="data"
- type="textarea"
- resize="none"
- :rows="element.options.rows"
- :style="{ width: element.options.width }"
- :placeholder="element.options.placeholder"
- :maxlength="parseInt(element.options.maxlength)"
- :show-word-limit="element.options.showWordLimit"
- :autosize="element.options.autosize"
- :clearable="element.options.clearable"
- :readonly="element.options.readonly"
- :disabled="disabled || element.options.disabled"
- />
- </template>
- <template v-if="element.type === 'number'">
- <el-input-number
- v-model="data"
- :style="{ width: element.options.width }"
- :max="element.options.max"
- :min="element.options.min"
- :disabled="disabled || element.options.disabled"
- controls-position="right"
- />
- </template>
- <template v-if="element.type === 'radio'">
- <el-radio-group
- v-model="data"
- :style="{ width: element.options.width }"
- :disabled="disabled || element.options.disabled"
- >
- <el-radio
- v-for="item of element.options.remote
- ? element.options.remoteOptions
- : element.options.options"
- :key="item.value"
- :label="item.value"
- :style="{
- display: element.options.inline ? 'inline-block' : 'block'
- }"
- >
- {{ element.options.showLabel ? item.label : item.value }}
- </el-radio>
- </el-radio-group>
- </template>
- <template v-if="element.type === 'checkbox'">
- <el-checkbox-group
- v-model="data"
- :style="{ width: element.options.width }"
- :disabled="disabled || element.options.disabled"
- >
- <el-checkbox
- v-for="item of element.options.remote
- ? element.options.remoteOptions
- : element.options.options"
- :key="item.value"
- :label="item.value"
- :style="{
- display: element.options.inline ? 'inline-block' : 'block'
- }"
- >
- {{ element.options.showLabel ? item.label : item.value }}
- </el-checkbox>
- </el-checkbox-group>
- </template>
- <template v-if="element.type === 'time'">
- <el-config-provider :locale="zhCn">
- <el-time-picker
- v-model="data"
- :placeholder="element.options.placeholder"
- :readonly="element.options.readonly"
- :editable="element.options.editable"
- :clearable="element.options.clearable"
- :format="element.options.format"
- :disabled="disabled || element.options.disabled"
- :style="{ width: element.options.width }"
- />
- </el-config-provider>
- </template>
- <template v-if="element.type === 'date'">
- <el-config-provider :locale="zhCn">
- <el-date-picker
- v-model="data"
- :placeholder="element.options.placeholder"
- :readonly="element.options.readonly"
- :editable="element.options.editable"
- :clearable="element.options.clearable"
- :format="element.options.format"
- :disabled="disabled || element.options.disabled"
- :style="{ width: element.options.width }"
- />
- </el-config-provider>
- </template>
- <template v-if="element.type === 'rate'">
- <el-rate
- v-model="data"
- :max="element.options.max"
- :allow-half="element.options.allowHalf"
- :disabled="disabled || element.options.disabled"
- />
- </template>
- <template v-if="element.type === 'select'">
- <template v-if="userInfo.userNameNeedTranslate == 1 && element.options.remoteFunc.indexOf('getSimpleActiveUserListNew') > -1">
- <personnelSearch
- v-model="data"
- :multiple="element.options.multiple"
- :placeholder="element.options.placeholder"
- :clearable="element.options.clearable"
- :filterable="element.options.filterable"
- :disabled="disabled || element.options.disabled"
- :url="element.options.remoteFunc"
- :size="config.size"
- :options="[]"
- :style="{ width: element.options.width }"
- @change="(value: any) => specializedHandleSelect(value, element)"
- >
- </personnelSearch>
- </template>
- <template v-else>
- <el-select
- v-model="data"
- :multiple="element.options.multiple"
- :placeholder="element.options.placeholder"
- :clearable="element.options.clearable"
- :filterable="element.options.filterable"
- :disabled="disabled || element.options.disabled"
- :style="{ width: element.options.width }"
- @change="(value: any) => specializedHandleSelect(value, element)"
- >
- <el-option
- v-for="item of element.options.remote
- ? element.options.remoteOptions
- : element.options.options"
- :key="item.value"
- :value="item.value"
- :label="element.options.showLabel ? item.label : item.value"
- />
- </el-select>
- </template>
- </template>
- <template v-if="element.type === 'switch'">
- <el-switch
- v-model="data"
- :active-text="element.options.activeText"
- :inactive-text="element.options.inactiveText"
- :disabled="disabled || element.options.disabled"
- />
- </template>
- <template v-if="element.type === 'slider'">
- <el-slider
- v-model="data"
- :min="element.options.min"
- :max="element.options.max"
- :step="element.options.step"
- :range="element.options.range"
- :disabled="disabled || element.options.disabled"
- :style="{ width: element.options.width }"
- />
- </template>
- <template v-if="element.type == 'text'">
- <span>{{ element.options.defaultValue }}</span>
- </template>
- <template v-if="element.type === 'img-upload'">
- <el-upload
- :name="element.options.file"
- :action="element.options.action"
- :accept="element.options.accept"
- :list-type="element.options.listType"
- :multiple="element.options.multiple"
- :limit="element.options.limit"
- :disabled="disabled || element.options.disabled"
- :on-success="handleUploadSuccess"
- >
- <template v-if="element.options.listType === 'picture-card'">
- <el-image
- v-if="element.options.defaultValue?.length"
- style=" width: 100%;height: 100%;"
- :preview-src-list="[
- '/api/sys/common/static/' + element.options.defaultValue
- ]"
- :src="'/api/sys/common/static/' + element.options.defaultValue"
- />
- <i v-else class="custom:insert" />
- </template>
- <el-button v-else>
- <i class="custom:img-upload mr-2" />点击上传
- </el-button>
- </el-upload>
- </template>
- <template v-if="element.type === 'download'" #label="{ label }">
- <a
- :href="`/api/sys/common/static/${element.options.defaultValue}?inline=1`"
- style="color: #606266;"
- target="_blank"
- >
- {{ label }}
- </a>
- </template>
- <template v-if="element.type === 'download'">
- <el-button
- style="margin-top: -4px;"
- type="text"
- @click="download(element.options.defaultValue, element.label)"
- >
- 下载
- </el-button>
- </template>
- <template v-if="element.type === 'cascader'">
- <el-cascader
- v-model="data"
- :options="element.options.remoteOptions"
- :placeholder="element.options.placeholder"
- :filterable="element.options.filterable"
- :clearable="element.options.clearable"
- :disabled="disabled || element.options.disabled"
- :style="{ width: element.options.width }"
- />
- </template>
- </el-form-item>
- </template>
- <script lang="ts" setup>
- import type { WidgetForm } from '@/config'
- import zhCn from "element-plus/es/locale/lang/zh-cn";
- import personnelSearch from '@/components/personnelSearch.vue';
- const { userInfo = {} } = JSON.parse(sessionStorage.getItem('storeInfo') || '{}')
- const props = defineProps<{
- config: WidgetForm['config']
- element: any
- model: any
- updatedModel: any
- disabled: boolean
- request?: Function
- widgetFormData?: any
- }>()
- const originData = props.model[props.element.model]
- const data = computed({
- get: () => props.model[props.element.model],
- set: (val) => {
- // eslint-disable-next-line vue/no-mutating-props
- props.model[props.element.model] = val
- if (JSON.stringify(originData) === JSON.stringify(val)) {
- Reflect.deleteProperty(props.updatedModel, props.element.model)
- }
- else {
- // eslint-disable-next-line vue/no-mutating-props
- props.updatedModel[props.element.model] = val
- }
- },
- })
- const handleUploadSuccess = (_res: any, _file: any, fileList: any[]) => {
- data.value = fileList
- }
- async function download(defaultValue: string, label: string) {
- const a = document.createElement('a')
- if (!props.request) return
- a.href = await props
- .request({
- url: `/sys/common/static/${defaultValue}`,
- responseType: 'blob',
- })
- .then((i: any) => {
- if (i.size === 0) return ''
- return URL.createObjectURL(i)
- })
- a.download = `${label}.${defaultValue.split('.')[1]}`
- a.click()
- }
- const emits = defineEmits(['updateWidgetForm'])
- const specializedHandleSelect = (val: any, element: any) => {
- const field = element.model
- if(field == 'customerId') {
- // console.log(props, '<===== props')
- let list = JSON.parse(JSON.stringify(props.widgetFormData))
- for(var i in list) {
- if(list[i].list[0].model == 'contactsId') {
- let item = list[i].list[0]
- const token: any = sessionStorage.getItem('token')
- // fetch(item.options.remoteFunc, {
- fetch(`${item.options.remoteFunc}?customerId=${val}`, {
- headers: {
- "Content-type": " application/x-www-form-urlencoded; charset=UTF-8",
- "Token": token
- }
- })
- .then(resp => resp.json())
- .then((json) => {
- const res = json.data
- if (res instanceof Array) {
- item.options.remoteOptions = res.map(data => ({
- label: data[item.options.props.label],
- value: data[item.options.props.value],
- children: data[item.options.props.children],
- }))
- }
- list[i].list[0].options = {...list[i].list[0].options, disabled: false, defaultValue: ''}
- })
- }
- }
- setTimeout(() => {
- console.log('开始执行')
- updateWidgetForm(list)
- }, 100)
- }
- }
- const updateWidgetForm = (list: any) => {
- emits('updateWidgetForm', list)
- }
- </script>
- <style scoped>
- :deep(.el-upload--picture-card) {
- width: 134px;
- height: 134px;
- }
- </style>
|