update
This commit is contained in:
parent
f0426f1f5a
commit
90f83588fd
@ -52,4 +52,13 @@ export function updateCommunity(id, data) {
|
|||||||
method: 'put',
|
method: 'put',
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 上传图片
|
||||||
|
export function uploadImage(data) {
|
||||||
|
return request({
|
||||||
|
url: '/api/upload/image',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
const env = {
|
const env = {
|
||||||
development: {
|
development: {
|
||||||
API_URL: 'http://localhost:8080'
|
API_URL: 'http://localhost:8000'
|
||||||
},
|
},
|
||||||
testing: {
|
testing: {
|
||||||
API_URL: process.env.VUE_APP_API_URL || 'https://api-dev.beefast.co'
|
API_URL: process.env.VUE_APP_API_URL || 'https://api-dev.beefast.co'
|
||||||
},
|
},
|
||||||
production: {
|
production: {
|
||||||
API_URL: process.env.VUE_APP_API_URL || 'http://api.example.com'
|
API_URL: process.env.VUE_APP_API_URL || 'http://api.beefast.co'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -52,6 +52,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
|
|
||||||
|
|
||||||
<a-modal
|
<a-modal
|
||||||
v-model:visible="mapVisible"
|
v-model:visible="mapVisible"
|
||||||
title="小区位置"
|
title="小区位置"
|
||||||
@ -97,19 +98,33 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<a-form-item label="群二维码" name="qy_group_qrcode">
|
<a-form-item label="群二维码" name="qy_group_qrcode">
|
||||||
<a-upload
|
<div class="qrcode-upload-wrapper">
|
||||||
v-model:file-list="fileList"
|
<a-upload
|
||||||
name="file"
|
v-model:file-list="fileList"
|
||||||
:action="uploadUrl"
|
name="file"
|
||||||
list-type="picture-card"
|
:customRequest="handleQRCodeUpload"
|
||||||
:max-count="1"
|
@remove="handleQRCodeRemove"
|
||||||
@change="handleQrcodeChange"
|
list-type="picture-card"
|
||||||
>
|
accept=".jpg,.jpeg,.png"
|
||||||
<div v-if="!fileList.length">
|
:max-count="1"
|
||||||
<plus-outlined />
|
@preview="previewQRCode"
|
||||||
<div style="margin-top: 8px">上传</div>
|
>
|
||||||
</div>
|
<div v-if="!fileList.length">
|
||||||
</a-upload>
|
<plus-outlined />
|
||||||
|
<div style="margin-top: 8px">上传</div>
|
||||||
|
</div>
|
||||||
|
</a-upload>
|
||||||
|
|
||||||
|
<!-- 添加预览模态框 -->
|
||||||
|
<a-modal
|
||||||
|
v-model:visible="previewVisible"
|
||||||
|
:title="previewTitle"
|
||||||
|
:footer="null"
|
||||||
|
@cancel="handlePreviewCancel"
|
||||||
|
>
|
||||||
|
<img style="width: 100%" :src="previewImage" />
|
||||||
|
</a-modal>
|
||||||
|
</div>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
</a-modal>
|
</a-modal>
|
||||||
@ -120,13 +135,13 @@
|
|||||||
<script>
|
<script>
|
||||||
import { defineComponent, ref, onMounted, nextTick } from 'vue'
|
import { defineComponent, ref, onMounted, nextTick } from 'vue'
|
||||||
import { message, Tag, Menu, Dropdown, Image, Upload } from 'ant-design-vue'
|
import { message, Tag, Menu, Dropdown, Image, Upload } from 'ant-design-vue'
|
||||||
import { getCommunityList, createCommunity, updateCommunityStatus, updateCommunity } from '@/api/community'
|
import { getCommunityList, createCommunity, updateCommunityStatus, updateCommunity, uploadImage } from '@/api/community'
|
||||||
import { loadAMap, createMap } from '@/utils/amap.js'
|
import { loadAMap, createMap } from '@/utils/amap.js'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import PageContainer from '@/components/PageContainer.vue'
|
import PageContainer from '@/components/PageContainer.vue'
|
||||||
import { DownOutlined, PlusOutlined } from '@ant-design/icons-vue'
|
import { DownOutlined, PlusOutlined } from '@ant-design/icons-vue'
|
||||||
import MapPicker from '@/components/MapPicker/index.vue'
|
import MapPicker from '@/components/MapPicker/index.vue'
|
||||||
|
import request from '../../utils/request'
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
PageContainer,
|
PageContainer,
|
||||||
@ -325,7 +340,9 @@ export default defineComponent({
|
|||||||
|
|
||||||
// 添加上传相关的响应式变量
|
// 添加上传相关的响应式变量
|
||||||
const fileList = ref([])
|
const fileList = ref([])
|
||||||
const uploadUrl = '/api/upload/image'
|
const previewVisible = ref(false)
|
||||||
|
const previewImage = ref('')
|
||||||
|
const previewTitle = ref('')
|
||||||
|
|
||||||
// 显示编辑模态框
|
// 显示编辑模态框
|
||||||
const handleEdit = (record) => {
|
const handleEdit = (record) => {
|
||||||
@ -376,6 +393,85 @@ export default defineComponent({
|
|||||||
fileList.value = []
|
fileList.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修改预览图片函数
|
||||||
|
const previewQRCode = async (file) => {
|
||||||
|
// 如果是已上传的图片,直接使用 url
|
||||||
|
if (file.url) {
|
||||||
|
previewImage.value = file.url
|
||||||
|
previewVisible.value = true
|
||||||
|
previewTitle.value = file.name || '群二维码预览'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是新上传的图片,需要处理 File 对象
|
||||||
|
if (file.originFileObj) {
|
||||||
|
try {
|
||||||
|
const preview = await getBase64(file.originFileObj)
|
||||||
|
previewImage.value = preview
|
||||||
|
previewVisible.value = true
|
||||||
|
previewTitle.value = file.name || '群二维码预览'
|
||||||
|
} catch (error) {
|
||||||
|
console.error('预览图片失败:', error)
|
||||||
|
message.error('预览失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭预览
|
||||||
|
const handlePreviewCancel = () => {
|
||||||
|
previewVisible.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件转base64
|
||||||
|
const getBase64 = (file) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const reader = new FileReader()
|
||||||
|
reader.readAsDataURL(file)
|
||||||
|
reader.onload = () => resolve(reader.result)
|
||||||
|
reader.onerror = error => reject(error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改上传处理函数
|
||||||
|
const handleQRCodeUpload = async ({ file, onSuccess, onError }) => {
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('file', file)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await request.post('/api/upload/image', formData, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.code === 200) {
|
||||||
|
formState.value.qy_group_qrcode = res.data.url
|
||||||
|
// 更新文件列表以支持预览
|
||||||
|
fileList.value = [{
|
||||||
|
uid: file.uid,
|
||||||
|
name: file.name,
|
||||||
|
status: 'done',
|
||||||
|
url: res.data.url
|
||||||
|
}]
|
||||||
|
message.success('上传成功')
|
||||||
|
onSuccess(res)
|
||||||
|
} else {
|
||||||
|
message.error(res.message || '上传失败')
|
||||||
|
onError(new Error(res.message || '上传失败'))
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('上传图片失败:', error)
|
||||||
|
message.error('上传失败')
|
||||||
|
onError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除二维码
|
||||||
|
const handleQRCodeRemove = (file) => {
|
||||||
|
formState.value.qy_group_qrcode = ''
|
||||||
|
fileList.value = []
|
||||||
|
}
|
||||||
|
|
||||||
// 统一提交处理
|
// 统一提交处理
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
formRef.value.validate().then(async () => {
|
formRef.value.validate().then(async () => {
|
||||||
@ -440,20 +536,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理二维码上传
|
|
||||||
const handleQrcodeChange = (info) => {
|
|
||||||
if (info.file.status === 'done') {
|
|
||||||
if (info.file.response.code === 200) {
|
|
||||||
formState.value.qy_group_qrcode = info.file.response.data.url
|
|
||||||
message.success('上传成功')
|
|
||||||
} else {
|
|
||||||
message.error(info.file.response.message || '上传失败')
|
|
||||||
}
|
|
||||||
} else if (info.file.status === 'error') {
|
|
||||||
message.error('上传失败')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchData()
|
fetchData()
|
||||||
})
|
})
|
||||||
@ -481,9 +563,14 @@ export default defineComponent({
|
|||||||
handleCancel,
|
handleCancel,
|
||||||
handleStatusChange,
|
handleStatusChange,
|
||||||
fileList,
|
fileList,
|
||||||
uploadUrl,
|
handleQRCodeUpload,
|
||||||
handleQrcodeChange,
|
handleQRCodeRemove,
|
||||||
handleEdit
|
handleEdit,
|
||||||
|
previewVisible,
|
||||||
|
previewImage,
|
||||||
|
previewTitle,
|
||||||
|
handlePreviewCancel,
|
||||||
|
previewQRCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -797,4 +884,26 @@ export default defineComponent({
|
|||||||
width: 104px;
|
width: 104px;
|
||||||
height: 104px;
|
height: 104px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.qrcode-upload-wrapper {
|
||||||
|
:deep(.ant-upload-list-picture-card-container) {
|
||||||
|
width: 104px;
|
||||||
|
height: 104px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-upload.ant-upload-select-picture-card) {
|
||||||
|
width: 104px;
|
||||||
|
height: 104px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-upload-list-picture-card .ant-upload-list-item) {
|
||||||
|
padding: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-upload-list-picture-card .ant-upload-list-item-thumbnail) {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
Loading…
Reference in New Issue
Block a user