资源选择器
This commit is contained in:
parent
1c9f69a53b
commit
09f08bc553
|
|
@ -89,6 +89,34 @@ export default {
|
||||||
upload: async function (data, config = {}) {
|
upload: async function (data, config = {}) {
|
||||||
return await http.post("upload", data, config);
|
return await http.post("upload", data, config);
|
||||||
},
|
},
|
||||||
|
asset_category: {
|
||||||
|
list: async function (data = {}) {
|
||||||
|
return await http.get("asset_category/list", data);
|
||||||
|
},
|
||||||
|
add: async function (data = {}) {
|
||||||
|
return await http.post("asset_category/add", data);
|
||||||
|
},
|
||||||
|
edit: async function (data = {}) {
|
||||||
|
return await http.put("asset_category/edit", data);
|
||||||
|
},
|
||||||
|
del: async function (data = {}) {
|
||||||
|
return await http.delete("asset_category/del", data);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
asset: {
|
||||||
|
list: async function (data = {}) {
|
||||||
|
return await http.get("asset/list", data);
|
||||||
|
},
|
||||||
|
move: async function (data = {}) {
|
||||||
|
return await http.put("asset/move", data);
|
||||||
|
},
|
||||||
|
del: async function (data = {}) {
|
||||||
|
return await http.delete("asset/del", data);
|
||||||
|
},
|
||||||
|
upload: async function (data, config = {}) {
|
||||||
|
return await http.post("asset/upload", data, config);
|
||||||
|
},
|
||||||
|
},
|
||||||
monitor: {
|
monitor: {
|
||||||
server: async function (data, config = {}) {
|
server: async function (data, config = {}) {
|
||||||
return await http.get("monitor/server", data, config);
|
return await http.get("monitor/server", data, config);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="pi-asset">
|
<div class="pi-asset">
|
||||||
<div class="file-item" v-for="(item, index) in value" :key="index" :style="style">
|
<div class="file-item" v-for="(item, index) in value" :key="index" :style="style">
|
||||||
<el-image v-if="obj.isImg(item)" :src="item" :style="style" :preview-src-list="[item]" fit="cover"
|
<el-image v-if="obj.isImg(item)" :src="config.API_URL + '/' + item" :style="style" :preview-src-list="[config.API_URL + '/' + item]" fit="cover"
|
||||||
preview-teleported :z-index="9999"></el-image>
|
preview-teleported :z-index="9999"></el-image>
|
||||||
<pi-player v-else-if="obj.isVideo(item)" :src="item" :options="videoOptions"></pi-player>
|
<pi-player v-else-if="obj.isVideo(item)" :src="config.API_URL + '/' + item" :options="videoOptions"></pi-player>
|
||||||
<el-icon v-else :style="style" style="color: #409eff;" :size="32">
|
<el-icon v-else :style="style" style="color: #409eff;" :size="32">
|
||||||
<component :is="'pi-icon-task'"/>
|
<component :is="'pi-icon-task'"/>
|
||||||
</el-icon>
|
</el-icon>
|
||||||
|
|
@ -26,6 +26,7 @@ import pickerDialog from "./picker.vue";
|
||||||
import assetConfig from "@/config/asset"
|
import assetConfig from "@/config/asset"
|
||||||
import piPlayer from '@/components/piPlayer'
|
import piPlayer from '@/components/piPlayer'
|
||||||
import {nextTick, ref, watch} from "vue";
|
import {nextTick, ref, watch} from "vue";
|
||||||
|
import config from "@/config"
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue'])
|
const emit = defineEmits(['update:modelValue'])
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
{{ node.label }}
|
{{ node.label }}
|
||||||
</span>
|
</span>
|
||||||
<span class="do">
|
<span class="do">
|
||||||
<el-icon @click.stop="editCategory(data)"><el-icon-edit/></el-icon>
|
<el-icon v-if="data.category_id != 0" @click.stop="editCategory(data)"><el-icon-edit/></el-icon>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -57,7 +57,7 @@
|
||||||
<p>{{ file.name }}</p>
|
<p>{{ file.name }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-for="item in data" :key="item[fileProps.fileName]" class="pi-file-select__item"
|
<div v-for="item in data" :key="item[fileProps.fileName]" class="pi-file-select__item"
|
||||||
:class="{active: value.includes(item[fileProps.url]) }" @click="select(item)">
|
:class="{active: active(item) }" @click="select(item)">
|
||||||
<div class="pi-file-select__item__file">
|
<div class="pi-file-select__item__file">
|
||||||
<div class="pi-file-select__item__checkbox" v-if="multiple">
|
<div class="pi-file-select__item__checkbox" v-if="multiple">
|
||||||
<el-icon>
|
<el-icon>
|
||||||
|
|
@ -70,7 +70,8 @@
|
||||||
</el-icon>
|
</el-icon>
|
||||||
</div>
|
</div>
|
||||||
<div class="pi-file-select__item__box"></div>
|
<div class="pi-file-select__item__box"></div>
|
||||||
<el-image v-if="obj.isImg(item[fileProps.url])" :src="item[fileProps.url]" fit="contain"
|
<el-image v-if="obj.isImg(item[fileProps.url])"
|
||||||
|
:src="config.API_URL + '/' + item[fileProps.url]" fit="contain"
|
||||||
lazy></el-image>
|
lazy></el-image>
|
||||||
<div v-else-if="obj.isVideo(item[fileProps.url])" class="item-video">
|
<div v-else-if="obj.isVideo(item[fileProps.url])" class="item-video">
|
||||||
<el-icon size="32px">
|
<el-icon size="32px">
|
||||||
|
|
@ -88,7 +89,8 @@
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
</div>
|
</div>
|
||||||
<div class="pi-file-select__pagination">
|
<div class="pi-file-select__pagination">
|
||||||
<el-pagination size="small" background layout="prev, pager, next" :total="total" :page-size="pageSize"
|
<el-pagination size="small" background layout="prev, pager, next" :total="total"
|
||||||
|
:page-size="pageSize"
|
||||||
v-model:currentPage="currentPage" @current-change="reload"></el-pagination>
|
v-model:currentPage="currentPage" @current-change="reload"></el-pagination>
|
||||||
</div>
|
</div>
|
||||||
<div class="pi-file-select__do">
|
<div class="pi-file-select__do">
|
||||||
|
|
@ -108,8 +110,9 @@ import assetConfig from "@/config/asset"
|
||||||
import saveDialog from "./save.vue";
|
import saveDialog from "./save.vue";
|
||||||
import moveDialog from "./move.vue";
|
import moveDialog from "./move.vue";
|
||||||
import * as imageConversion from 'image-conversion';
|
import * as imageConversion from 'image-conversion';
|
||||||
import {ref, onMounted, nextTick, getCurrentInstance} from "vue"
|
import {ref, onMounted, nextTick, getCurrentInstance, computed} from "vue"
|
||||||
import tools from "@/utils/tools"
|
import tools from "@/utils/tools"
|
||||||
|
import config from "@/config"
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
open
|
open
|
||||||
|
|
@ -164,7 +167,7 @@ async function getMenu() {
|
||||||
const res = await assetConfig.menuListObj();
|
const res = await assetConfig.menuListObj();
|
||||||
menu.value = tools.makeTreeData(res.data, 0, "category_id")
|
menu.value = tools.makeTreeData(res.data, 0, "category_id")
|
||||||
menu.value.unshift({
|
menu.value.unshift({
|
||||||
'category_id': '',
|
'category_id': 0,
|
||||||
'category_name': '未分类',
|
'category_name': '未分类',
|
||||||
'pid': 0
|
'pid': 0
|
||||||
})
|
})
|
||||||
|
|
@ -179,7 +182,7 @@ async function getData() {
|
||||||
[assetConfig.request.pageSize]: pageSize.value,
|
[assetConfig.request.pageSize]: pageSize.value,
|
||||||
};
|
};
|
||||||
reqData.type = props.type
|
reqData.type = props.type
|
||||||
reqData.file_name = file_name.value
|
reqData.ori_name = file_name.value
|
||||||
const res = await assetConfig.fileListObj(reqData);
|
const res = await assetConfig.fileListObj(reqData);
|
||||||
const parseData = assetConfig.listParseData(res);
|
const parseData = assetConfig.listParseData(res);
|
||||||
data.value = parseData.rows
|
data.value = parseData.rows
|
||||||
|
|
@ -203,37 +206,56 @@ function search() {
|
||||||
getData()
|
getData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function active(item) {
|
||||||
|
if (props.multiple) {
|
||||||
|
let choice = false;
|
||||||
|
value.value.forEach(i => {
|
||||||
|
if (i[assetConfig.fileProps.id] === item[assetConfig.fileProps.id]) {
|
||||||
|
choice = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return choice
|
||||||
|
} else {
|
||||||
|
return value.value[assetConfig.fileProps.id] === item[assetConfig.fileProps.id]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function select(item) {
|
function select(item) {
|
||||||
const itemUrl = item[fileProps.value.url]
|
|
||||||
if (props.multiple) {
|
if (props.multiple) {
|
||||||
if (value.value.length >= props.max) {
|
if (value.value.length >= props.max) {
|
||||||
proxy.$message.error("选择文件过多")
|
proxy.$message.error("选择文件过多")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (value.value.includes(itemUrl)) {
|
if (active(item)) {
|
||||||
value.value.splice(value.value.findIndex(f => f == itemUrl), 1)
|
value.value.splice(value.value.findIndex(f => f[assetConfig.fileProps.id] === item[assetConfig.fileProps.id]), 1)
|
||||||
} else {
|
} else {
|
||||||
value.value.push(itemUrl)
|
value.value.push(item)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (value.value.includes(itemUrl)) {
|
if (value.value[assetConfig.fileProps.id] === item[assetConfig.fileProps.id]) {
|
||||||
value.value = ''
|
value.value = ''
|
||||||
} else {
|
} else {
|
||||||
value.value = itemUrl
|
value.value = item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
emit('success', value.value);
|
if (props.multiple) {
|
||||||
|
emit('success', value.value.map(i => i[assetConfig.fileProps.url]));
|
||||||
|
} else {
|
||||||
|
emit('success', value.value[assetConfig.fileProps.url]);
|
||||||
|
}
|
||||||
visible.value = false
|
visible.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
async function delFile() {
|
async function delFile() {
|
||||||
const _value = JSON.parse(JSON.stringify(value.value))
|
const _value = JSON.parse(JSON.stringify(value.value))
|
||||||
const url = props.multiple ? _value.toString() : _value;
|
const ids = props.multiple ? _value.map(i => i[assetConfig.fileProps.id]) : [_value[assetConfig.fileProps.id]];
|
||||||
if (!url) return;
|
if (!ids) return;
|
||||||
const res = await assetConfig.delFileObj({url: url});
|
const res = await assetConfig.delFileObj({ids: ids});
|
||||||
|
// 删除文件成功,取消选择
|
||||||
|
value.value = props.multiple ? [] : ''
|
||||||
proxy.$message.success(res.msg)
|
proxy.$message.success(res.msg)
|
||||||
getData()
|
getData()
|
||||||
}
|
}
|
||||||
|
|
@ -246,11 +268,10 @@ function moveFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function moveSuccess(category_id) {
|
async function moveSuccess(category_id) {
|
||||||
console.log(category_id)
|
|
||||||
const _value = JSON.parse(JSON.stringify(value.value))
|
const _value = JSON.parse(JSON.stringify(value.value))
|
||||||
const url = props.multiple ? _value.toString() : _value;
|
const ids = props.multiple ? _value.map(i=>i[assetConfig.fileProps.id]) :[ _value[assetConfig.fileProps.id]];
|
||||||
if (!url) return;
|
if (!ids) return;
|
||||||
const res = await assetConfig.moveFileObj({url: url, category_id: category_id});
|
const res = await assetConfig.moveFileObj({ids: ids, category_id: category_id});
|
||||||
proxy.$message.success(res.msg)
|
proxy.$message.success(res.msg)
|
||||||
getData()
|
getData()
|
||||||
}
|
}
|
||||||
|
|
@ -311,12 +332,9 @@ function clearFiles(file) {
|
||||||
function uploadSuccess(res, file) {
|
function uploadSuccess(res, file) {
|
||||||
fileList.value.splice(fileList.value.findIndex(f => f.uid == file.uid), 1)
|
fileList.value.splice(fileList.value.findIndex(f => f.uid == file.uid), 1)
|
||||||
var response = assetConfig.uploadParseData(res);
|
var response = assetConfig.uploadParseData(res);
|
||||||
data.value.unshift({
|
data.value.unshift(response)
|
||||||
[fileProps.value.fileName]: response.fileName,
|
|
||||||
[fileProps.value.url]: response.url
|
|
||||||
})
|
|
||||||
if (!props.multiple) {
|
if (!props.multiple) {
|
||||||
value.value = response.url
|
value.value = response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -337,13 +355,13 @@ function editCategory(data) {
|
||||||
function addCategory() {
|
function addCategory() {
|
||||||
dialog.value.save = true
|
dialog.value.save = true
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
saveRef.value.open('add',menu.value)
|
saveRef.value.open('add', menu.value, null, menuRef.value.getCurrentKey())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function delCategory() {
|
async function delCategory() {
|
||||||
var CheckedNodes = menuRef.value.getCheckedNodes()
|
var CheckedNodes = menuRef.value.getCheckedNodes()
|
||||||
if (CheckedNodes.length == 0) {
|
if (CheckedNodes.length === 0) {
|
||||||
proxy.$message.warning("请选择需要删除的项")
|
proxy.$message.warning("请选择需要删除的项")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -354,12 +372,11 @@ async function delCategory() {
|
||||||
confirmButtonClass: 'el-button--danger'
|
confirmButtonClass: 'el-button--danger'
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
})
|
})
|
||||||
if (confirm != 'confirm') {
|
if (confirm !== 'confirm') {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
menuLoading.value = true
|
menuLoading.value = true
|
||||||
var ids = CheckedNodes.map(item => item.category_id)
|
var res = await assetConfig.menuDelObj({ids: CheckedNodes.map(item => item.category_id)})
|
||||||
var res = await assetConfig.menuDelObj({ids: ids.toString()})
|
|
||||||
menuLoading.value = false
|
menuLoading.value = false
|
||||||
proxy.$message.success(res.msg)
|
proxy.$message.success(res.msg)
|
||||||
CheckedNodes.forEach(item => {
|
CheckedNodes.forEach(item => {
|
||||||
|
|
|
||||||
|
|
@ -59,12 +59,15 @@ let menuProps = ref({
|
||||||
checkStrictly: true
|
checkStrictly: true
|
||||||
})
|
})
|
||||||
|
|
||||||
function open(_mode = 'add', _menu = null, data = null) {
|
function open(_mode = 'add', _menu = null, data = null, pid=null) {
|
||||||
mode.value = _mode;
|
mode.value = _mode;
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
if (_menu) {
|
if (_menu) {
|
||||||
menu.value = _menu
|
menu.value = _menu
|
||||||
}
|
}
|
||||||
|
if (pid) {
|
||||||
|
form.value.pid = pid
|
||||||
|
}
|
||||||
if (data) {
|
if (data) {
|
||||||
Object.assign(form.value, data)
|
Object.assign(form.value, data)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
import api from "@/api";
|
import api from "@/api";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
uploadObj: api.system.upload,
|
uploadObj: api.system.asset.upload,
|
||||||
fileListObj: api.system.file.list,
|
fileListObj: api.system.asset.list,
|
||||||
moveFileObj: api.system.file.move,
|
moveFileObj: api.system.asset.move,
|
||||||
delFileObj: api.system.file.del,
|
delFileObj: api.system.asset.del,
|
||||||
menuListObj: api.system.category.list,
|
menuListObj: api.system.asset_category.list,
|
||||||
menuAddObj: api.system.category.add,
|
menuAddObj: api.system.asset_category.add,
|
||||||
menuEditObj: api.system.category.edit,
|
menuEditObj: api.system.asset_category.edit,
|
||||||
menuDelObj: api.system.category.del,
|
menuDelObj: api.system.asset_category.del,
|
||||||
successCode: 200,
|
successCode: 200,
|
||||||
maxSize: 20,
|
maxSize: 20,
|
||||||
max: 99,
|
max: 99,
|
||||||
uploadParseData: function (res) {
|
uploadParseData: function (res) {
|
||||||
return {
|
return Object.assign({
|
||||||
fileName: res.data.fileName,
|
fileName: res.data.fileName,
|
||||||
url: res.data.filePath
|
url: res.data.filePath
|
||||||
}
|
}, res.data)
|
||||||
},
|
},
|
||||||
listParseData: function (res) {
|
listParseData: function (res) {
|
||||||
return {
|
return {
|
||||||
|
|
@ -38,7 +38,8 @@ export default {
|
||||||
children: 'children'
|
children: 'children'
|
||||||
},
|
},
|
||||||
fileProps: {
|
fileProps: {
|
||||||
fileName: 'file_name',
|
id: 'asset_id',
|
||||||
|
fileName: 'ori_name',
|
||||||
url: 'url'
|
url: 'url'
|
||||||
},
|
},
|
||||||
fileType(type: string) {
|
fileType(type: string) {
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,7 @@
|
||||||
<el-switch v-model="form.enable" :active-value="1" :inactive-value="0"></el-switch>
|
<el-switch v-model="form.enable" :active-value="1" :inactive-value="0"></el-switch>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="备注" prop="memo">
|
<el-form-item label="备注" prop="memo">
|
||||||
<pi-editor v-model="form.memo"></pi-editor>
|
<el-input type="textarea" v-model="form.memo" placeholder="请输入备注" clearable></el-input>
|
||||||
<!-- <el-input type="textarea" v-model="form.memo" placeholder="请输入备注" clearable></el-input>-->
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
|
|
@ -35,7 +34,8 @@
|
||||||
import {getCurrentInstance, ref} from 'vue'
|
import {getCurrentInstance, ref} from 'vue'
|
||||||
import api from "@/api/index.js"
|
import api from "@/api/index.js"
|
||||||
import piCron from "@/components/piCron"
|
import piCron from "@/components/piCron"
|
||||||
import piEditor from "@/components/piEditor"
|
import piAsset from "@/components/piAsset"
|
||||||
|
// import piEditor from "@/components/piEditor"
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
open
|
open
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</pi-table>
|
</pi-table>
|
||||||
<save-dialog v-if="dialogSave" ref="saveRef" @closed="dialogSave=false"></save-dialog>
|
<save-dialog v-if="dialogSave" ref="saveRef" @closed="dialogSave=false" @success="tableRef.refresh()"></save-dialog>
|
||||||
<show-dialog v-if="dialogShow" ref="showRef" @closed="dialogShow=false"></show-dialog>
|
<show-dialog v-if="dialogShow" ref="showRef" @closed="dialogShow=false"></show-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue