|
@@ -1,13 +1,7 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<div style="display: flex">
|
|
|
- <Input
|
|
|
- class="upload-input"
|
|
|
- :value="imageUrls"
|
|
|
- @focus="onFocus"
|
|
|
- @change="onInputChange"
|
|
|
- @blur="onBlur"
|
|
|
- />
|
|
|
+ <Input class="upload-input" :value="imageUrls" disabled />
|
|
|
<BasicUpload
|
|
|
:maxSize="20"
|
|
|
:maxNumber="10"
|
|
@@ -27,11 +21,11 @@
|
|
|
<span class="tip-span" v-if="tipShow">{{ tip }}</span>
|
|
|
</div>
|
|
|
|
|
|
- <div class="image-list" v-if="file_list">
|
|
|
+ <div class="image-list" v-if="file_list.length">
|
|
|
<div v-for="(item, index) in file_list" :key="index">
|
|
|
- <div class="image-item" v-if="imageUrls.split(',').includes(item.url)">
|
|
|
- <div class="image-wrap"> <a-image width="70px" :src="item.url" /></div>
|
|
|
- <div class="dele-image" @click="deleteImage(item.url)">
|
|
|
+ <div class="image-item" v-if="item !== ''">
|
|
|
+ <div class="image-wrap"> <a-image width="70px" :src="imgUrlPrefix + item" /></div>
|
|
|
+ <div class="dele-image" @click="deleteImage(item, index)">
|
|
|
<Icon icon="ri:delete-bin-5-fill" />
|
|
|
</div>
|
|
|
</div>
|
|
@@ -41,11 +35,12 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
- import { defineComponent, reactive, toRefs } from 'vue';
|
|
|
+ import { defineComponent, watch, reactive, toRefs } from 'vue';
|
|
|
import { BasicUpload } from '/@/components/Upload';
|
|
|
// import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
import { uploadApi } from '/@/api/sys/upload';
|
|
|
import ChooseModal from './ChooseModal.vue';
|
|
|
+ import { useGlobSetting } from '/@/hooks/setting';
|
|
|
import { useModal } from '/@/components/Modal';
|
|
|
import { Image, Input } from 'ant-design-vue';
|
|
|
import Icon from '/@/components/Icon';
|
|
@@ -57,67 +52,71 @@
|
|
|
errMsg: { type: String, default: '' },
|
|
|
rules: { type: Array, default: [] },
|
|
|
};
|
|
|
+ interface PropsType {
|
|
|
+ value: string;
|
|
|
+ tip: string;
|
|
|
+ type: string;
|
|
|
+ errMsg: string;
|
|
|
+ rules: [];
|
|
|
+ }
|
|
|
export default defineComponent({
|
|
|
components: { BasicUpload, ChooseModal, aImage: Image, Input, Icon },
|
|
|
props,
|
|
|
emits: ['change'],
|
|
|
setup(props, { emit }) {
|
|
|
// const { createMessage } = useMessage();
|
|
|
+ const { imgUrlPrefix } = useGlobSetting();
|
|
|
const [chooseModalRegister, { openModal }] = useModal();
|
|
|
function openChooseModal() {
|
|
|
openModal(true);
|
|
|
}
|
|
|
const state = reactive({
|
|
|
imageUrls: props.value,
|
|
|
- file_list: [] as object[],
|
|
|
+ file_list: [] as string[],
|
|
|
tipShow: false,
|
|
|
});
|
|
|
-
|
|
|
- function deleteImage(url) {
|
|
|
+ state.file_list = props.value.split(',');
|
|
|
+ function deleteImage(url, index) {
|
|
|
const arr = state.imageUrls.split(',');
|
|
|
- arr.splice(
|
|
|
- arr.findIndex((item) => item === url),
|
|
|
- 1
|
|
|
- );
|
|
|
+ // arr.splice(
|
|
|
+ // arr.findIndex((item) => item === url),
|
|
|
+ // 1
|
|
|
+ // );
|
|
|
+ console.log(`url`, url);
|
|
|
+ arr.splice(index, 1);
|
|
|
state.imageUrls = arr.toString();
|
|
|
+ emit('change', state.imageUrls);
|
|
|
}
|
|
|
function checked(imgs) {
|
|
|
if (props.type === 'image') {
|
|
|
state.imageUrls = imgs[0].url;
|
|
|
} else {
|
|
|
+ let urls: string[] = [];
|
|
|
imgs.map((item) => {
|
|
|
- state.imageUrls += item.url + ',';
|
|
|
+ urls.push(item.url);
|
|
|
});
|
|
|
+ state.imageUrls += ',' + urls.toString();
|
|
|
}
|
|
|
emit('change', state.imageUrls);
|
|
|
- console.log(`imgs`, imgs);
|
|
|
}
|
|
|
|
|
|
- function onInputChange(e) {
|
|
|
- state.imageUrls = e.target.value;
|
|
|
- }
|
|
|
- function onFocus() {
|
|
|
- state.tipShow = true;
|
|
|
- }
|
|
|
- function onBlur() {
|
|
|
- state.tipShow = false;
|
|
|
- }
|
|
|
+ watch(props, (props: PropsType) => {
|
|
|
+ state.file_list = props.value.split(',');
|
|
|
+ });
|
|
|
|
|
|
return {
|
|
|
handleChange: (list: string[]) => {
|
|
|
if (props.type === 'image') {
|
|
|
state.imageUrls = list[0];
|
|
|
} else {
|
|
|
- state.imageUrls = list.join(',');
|
|
|
+ state.imageUrls = list.toString();
|
|
|
}
|
|
|
emit('change', state.imageUrls);
|
|
|
},
|
|
|
checked,
|
|
|
+ imgUrlPrefix,
|
|
|
openChooseModal,
|
|
|
deleteImage,
|
|
|
- onInputChange,
|
|
|
- onFocus,
|
|
|
- onBlur,
|
|
|
uploadApi,
|
|
|
chooseModalRegister,
|
|
|
openModal,
|