|
@@ -1,27 +1,27 @@
|
|
|
<script setup>
|
|
|
import { ref, reactive } from 'vue'
|
|
|
import {InfoFilled,Search} from '@element-plus/icons-vue'
|
|
|
+import {apiImgSource,apiMediaCommon} from '@/api/media'
|
|
|
+import {cloneDeep} from 'lodash'
|
|
|
const tableQuery = reactive({
|
|
|
keyWord:'',
|
|
|
+ labels:'',
|
|
|
currentPage:1,
|
|
|
pageSize:10,
|
|
|
totals:0,
|
|
|
+ sortType:''
|
|
|
})
|
|
|
|
|
|
const tableColumns = [
|
|
|
- {label:'图片预览',key:'cover',},
|
|
|
- {label:'图片名称',key:'name',},
|
|
|
- {label:'添加时间',key:'time',width:250,sortable:true},
|
|
|
- {label:'关联标签',key:'label',},
|
|
|
+ {label:'图片预览',key:'SrcUrl',},
|
|
|
+ {label:'图片名称',key:'ImgName',},
|
|
|
+ {label:'添加时间',key:'CreatedTime',width:250,sortable:true},
|
|
|
+ {label:'关联标签',key:'PermissionName',},
|
|
|
]
|
|
|
let picUploadShow = ref(false)
|
|
|
let curPicData = ref({})
|
|
|
function handlePicUploadShow(data={}){
|
|
|
- curPicData.value = {
|
|
|
- imgUrl:data.imgUrl||'',
|
|
|
- name:data.name||'',
|
|
|
- labels:data.labels||''
|
|
|
- }
|
|
|
+ curPicData.value = cloneDeep(data)
|
|
|
picUploadShow.value = true
|
|
|
}
|
|
|
function handleEdit(data){
|
|
@@ -38,22 +38,76 @@ function handleDelete(data){
|
|
|
}
|
|
|
)
|
|
|
.then(() => {
|
|
|
- ElMessage.success('删除成功')
|
|
|
+ apiImgSource.deleteImgSource({
|
|
|
+ ImageId:data.Id
|
|
|
+ }).then(res=>{
|
|
|
+ if(res.Ret!==200) return
|
|
|
+ ElMessage.success('删除成功')
|
|
|
+ getTableData()
|
|
|
+ })
|
|
|
}).catch(() => {})
|
|
|
}
|
|
|
+const labelOptions = ref([])
|
|
|
+function getLabelOptions(){
|
|
|
+ apiMediaCommon.getPermissionList().then(res=>{
|
|
|
+ if(res.Ret!==200) return
|
|
|
+ labelOptions.value = res.Data.List||[]
|
|
|
+ })
|
|
|
+}
|
|
|
+getLabelOptions()
|
|
|
const tableData = ref([])
|
|
|
function getTableData(){
|
|
|
- tableData.value = [
|
|
|
- {
|
|
|
- name:'aaa',
|
|
|
- time:'2024-08-02 12:30'
|
|
|
- }
|
|
|
- ]
|
|
|
+ apiImgSource.getImgSourceList({
|
|
|
+ KeyWord:tableQuery.keyWord,
|
|
|
+ PermissionIds:Array.isArray(tableQuery.labels)?tableQuery.labels.join(','):'',
|
|
|
+ SortType:tableQuery.sortType,
|
|
|
+ CurrentIndex:tableQuery.currentPage,
|
|
|
+ PageSize:tableQuery.pageSize
|
|
|
+ }).then(res=>{
|
|
|
+ if(res.Ret!==200) return
|
|
|
+ tableData.value = res.Data.List||[]
|
|
|
+ tableQuery.totals = res.Data.Paging.Totals||0
|
|
|
+ })
|
|
|
}
|
|
|
getTableData()
|
|
|
-function handlePageChange(){}
|
|
|
-
|
|
|
-function handleSavePic(){}
|
|
|
+function handlePageChange(page){
|
|
|
+ tableQuery.currentPage = page
|
|
|
+ getTableData()
|
|
|
+}
|
|
|
+function handleUploadImg(file){
|
|
|
+ //图片大小和格式限制
|
|
|
+ const {size,type} = file.file
|
|
|
+ const sizeLimit = 500*1024
|
|
|
+ if(!['image/png','image/jpeg'].includes(type)){
|
|
|
+ ElMessage.warning('仅支持png、jpg格式的图片')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(size>sizeLimit){
|
|
|
+ ElMessage.warning('资源库图片不能超过500kb')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let form = new FormData();
|
|
|
+ form.append('File',file.file);
|
|
|
+ apiImgSource.uploadImgFile(form).then(res=>{
|
|
|
+ if(res.Ret!==200) return
|
|
|
+ curPicData.value.SrcUrl = res.Data?.Url||''
|
|
|
+ })
|
|
|
+}
|
|
|
+async function handleSavePic(){
|
|
|
+ //rule check
|
|
|
+ const params = {
|
|
|
+ ImageName:curPicData.value.ImgName,
|
|
|
+ SrcUrl:curPicData.value.SrcUrl,
|
|
|
+ PermissionId:curPicData.value.PermissionId
|
|
|
+ }
|
|
|
+ const res = curPicData.value.Id
|
|
|
+ ? await apiImgSource.editImgSource({...params,ImageId:curPicData.value.Id})
|
|
|
+ :await apiImgSource.addImgSource(params)
|
|
|
+ if(res.Ret!==200) return
|
|
|
+ ElMessage.success(`${curPicData.value.Id?'编辑':'添加'}成功`)
|
|
|
+ getTableData()
|
|
|
+ picUploadShow.value = false
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
@@ -68,8 +122,22 @@ function handleSavePic(){}
|
|
|
>
|
|
|
<el-icon style="margin-left: 5px;"><InfoFilled /></el-icon>
|
|
|
</el-tooltip>
|
|
|
- <el-cascader></el-cascader>
|
|
|
- <el-input style="width:426px;" :prefix-icon="Search" clearable placeholder="请输入图片名称"></el-input>
|
|
|
+ <el-cascader v-model="tableQuery.labels" @change="handlePageChange(1)" placeholder="标签"
|
|
|
+ :options="labelOptions"
|
|
|
+ collapse-tags
|
|
|
+ collapse-tags-tooltip
|
|
|
+ :props="{
|
|
|
+ value:'id',
|
|
|
+ label:'name',
|
|
|
+ emitPath:false,
|
|
|
+ multiple:true
|
|
|
+ }"
|
|
|
+ ></el-cascader>
|
|
|
+ <el-input style="width:426px;" :prefix-icon="Search" clearable
|
|
|
+ placeholder="请输入图片名称"
|
|
|
+ v-model="tableQuery.keyWord"
|
|
|
+ @input="handlePageChange(1)"
|
|
|
+ />
|
|
|
</div>
|
|
|
<div class="table-box">
|
|
|
<el-table stripe border :data="tableData">
|
|
@@ -78,10 +146,16 @@ function handleSavePic(){}
|
|
|
v-for="column in tableColumns" :key="column.key"
|
|
|
:prop="column.key" :label="column.label" :sortable="column.sortable" :width="column.width">
|
|
|
<template #default="{row}">
|
|
|
- <div v-if="column.key==='cover'" style="color:#086CE0;cursor: pointer;">
|
|
|
- <img class="row-img" :src="row[column.key]||''">
|
|
|
+ <div v-if="column.key==='SrcUrl'" style="color:#086CE0;cursor: pointer;">
|
|
|
+ <el-image
|
|
|
+ v-if="row[column.key]"
|
|
|
+ fit="cover"
|
|
|
+ :src="row[column.key]||''"
|
|
|
+ :preview-src-list="[row[column.key]||'']"
|
|
|
+ style="display: inline-block;width:60px;height: 60px;" preview-teleported/>
|
|
|
+ <span v-else style="display: inline-block;width:60px;height: 60px;line-height: 60px;">-</span>
|
|
|
</div>
|
|
|
- <span v-else>{{ row[column.key] }}</span>
|
|
|
+ <span v-else>{{ row[column.key]||'-' }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
<el-table-column label="操作">
|
|
@@ -102,21 +176,32 @@ function handleSavePic(){}
|
|
|
/>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <el-dialog v-model="picUploadShow" :title="curPicData.id?'编辑图片':'添加图片'" width="646px" draggable>
|
|
|
+ <el-dialog v-model="picUploadShow" :title="curPicData.Id?'编辑图片':'添加图片'" width="646px" draggable>
|
|
|
<div class="content-wrap">
|
|
|
<el-form label-width="95px" label-position="left">
|
|
|
<el-form-item label="照片">
|
|
|
<ImageUpload
|
|
|
- :imgUrl="curPicData.imgUrl"
|
|
|
+ :imgUrl="curPicData.SrcUrl"
|
|
|
+ uploadHint="支持jpg、jpeg、png等格式,建议上传宽高比例为3:4的图片"
|
|
|
width="90px"
|
|
|
height="120px"
|
|
|
+ @upload="handleUploadImg"
|
|
|
+ @remove="curPicData.SrcUrl=''"
|
|
|
></ImageUpload>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="图片名称">
|
|
|
- <el-input v-model="curPicData.name" placeholder="请输入图片名称"></el-input>
|
|
|
+ <el-input v-model="curPicData.ImgName" placeholder="请输入图片名称"></el-input>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="关联标签">
|
|
|
- <el-cascader v-model="curPicData.labels" placeholder="请选择关联品种"></el-cascader>
|
|
|
+ <el-cascader v-model="curPicData.PermissionId" placeholder="请选择关联品种"
|
|
|
+ :options="labelOptions"
|
|
|
+ :props="{
|
|
|
+ value:'id',
|
|
|
+ label:'name',
|
|
|
+ emitPath:false,
|
|
|
+ multiple:false
|
|
|
+ }"
|
|
|
+ ></el-cascader>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
</div>
|