x-php-Admin/src/components/xTable/columnItem.vue

138 lines
5.6 KiB
Vue
Raw Normal View History

2023-07-13 00:44:51 +00:00
<template>
2023-12-26 10:08:34 +00:00
<div style="display: flex;">
2024-01-10 08:57:58 +00:00
<el-badge v-if="item.status && item.status.key && row[item.status.key]" is-dot class="item" :type="item.status.type || 'primary'" style="width: 10px;cursor: pointer;margin-top: 10px;"></el-badge>
2024-01-31 07:17:45 +00:00
<x-avatar v-if="item.columntype == 'avatar' || item.component == 'avatar'" :name="item.name" :options="bind" :data="row"></x-avatar>
<el-badge v-else-if="item.columntype == 'badge' || item.columntype == 'imagegroup'" :value="getType(row[item.name])" @click="handleClick(row, item)" v-bind="bind" style="cursor: pointer; "></el-badge>
<el-link v-else-if="item.columntype == 'link'" v-bind="bind" @click="handleClick(row, item)"> {{ row[item.name] }} </el-link>
2023-12-27 05:46:43 +00:00
<el-image v-else-if="item.columntype == 'image'" :preview-src-list="[getImg(row[item.name])]" :preview-teleported="true" hide-on-click-modal="true" lazy="true" style="max-width: 60px; height: 26px; border-radius: 2px;" fit="cover" :src="getImg(row[item.name])">
2023-07-17 10:22:43 +00:00
<template #error>
2023-12-27 05:46:43 +00:00
<div class="image-slot">
无图
</div>
</template>
2023-07-17 10:22:43 +00:00
</el-image>
2023-12-27 05:46:43 +00:00
<input v-else-if="item.columntype == 'input'" @click="handleClick(row, item)" style="cursor: pointer; " class="el-input__inner" type="text" readonly :value="row[item.name]">
2024-01-31 07:17:45 +00:00
<p v-else-if="item.columntype == 'status'" :style="item.style">
2024-01-30 15:24:43 +00:00
<template v-for="{ value, type = 'success', label, options={} } in options">
2024-01-31 07:17:45 +00:00
<x-status-indicator :key="value" pulse :type="type" :label="label" @click="handleClick(row, options || item)" v-if="value == row[item.name]"></x-status-indicator>
2023-12-27 05:46:43 +00:00
</template>
2023-07-13 00:44:51 +00:00
</p>
2023-12-27 05:46:43 +00:00
<p v-else-if="item.columntype == 'button'">
2024-01-30 15:24:43 +00:00
<span v-if="options && options.length > 0">
<template v-for="(op, index) in options">
2024-01-31 07:17:45 +00:00
<el-button @click="handleClick(row, op.options || item)" :key="index" type="warning" size="small" v-bind="op" v-if="op.value == row[item.name]">
{{ op.label }}
</el-button>
</template>
</span>
2024-01-31 07:17:45 +00:00
<el-button v-else @click="handleClick(row, item)" type="warning" v-bind="bind"> {{ row[item.name] }} </el-button>
2024-01-05 11:03:07 +00:00
</p>
<p v-else-if="item.columntype == 'text'">
2024-01-31 07:17:45 +00:00
<el-text v-bind="bind" v-if="item.copy" v-copy="row[item.copy]" style="cursor: pointer;display: inline;"> {{ row[item.name] }} </el-text>
<el-text v-bind="bind" v-else @click="handleClick(row, item)" style="cursor: pointer;display: inline;"> {{ row[item.name] }} </el-text>
2024-01-05 11:03:07 +00:00
</p>
2023-12-27 05:46:43 +00:00
<p v-else-if="item.columntype == 'tag' || item.columntype == 'time'" @click="handleClick(row, item)" v-time.tip="row[item.name]"></p>
2023-11-21 11:05:35 +00:00
<slot v-else :name="item.name">
2024-01-31 07:17:45 +00:00
{{ item.columntype == 'select' && options ? getNameByValue(row[item.name], options) : row[item.name] }}
2023-07-17 10:22:43 +00:00
</slot>
</div>
2023-07-13 00:44:51 +00:00
</template>
<style scoped>
2024-01-04 10:53:32 +00:00
.el-badge {
display: inherit;
}
</style>
2023-07-13 00:44:51 +00:00
<script>
2023-12-27 05:46:43 +00:00
export default {
name: 'XTableColumnItem',
props: {
item: {
type: Object, default: () => ({
2024-01-31 07:17:45 +00:00
options: [],
2024-01-30 16:05:23 +00:00
bind: {},
2023-12-27 05:46:43 +00:00
})
2023-07-13 00:44:51 +00:00
},
2023-12-27 05:46:43 +00:00
row: { type: Object, default: () => { } },
},
2024-01-30 15:24:43 +00:00
computed: {
options() {
2024-01-30 16:05:23 +00:00
return this.item.options.items || (Array.isArray(this.item.options) ? this.item.options : []); // 兼容旧版
2024-01-30 15:24:43 +00:00
},
2024-01-31 07:17:45 +00:00
bind() {
const { bind, options } = this.item;
return bind || (this.isPlainObject(options) ? options : {});
},
2024-01-30 15:24:43 +00:00
},
2023-12-27 05:46:43 +00:00
methods: {
2024-01-31 07:17:45 +00:00
isPlainObject(obj) {
return typeof obj === 'object' && obj !== null && !Array.isArray(obj);
},
2023-12-27 05:46:43 +00:00
handleClick(row, item) {
2023-09-05 07:23:52 +00:00
2023-12-27 05:46:43 +00:00
// 打开新窗口链接
if (item.open && item.open.name && row[item.open.name]?.trim()) {
window.open(row[item.open.name], item.open.target || "_blank");
2023-12-27 05:46:43 +00:00
return;
}
2024-01-30 07:32:44 +00:00
// 打开路由跳转
else if (item.router && item.router.path) {
var param = Object.assign({}, { [item.router.key]: row[item.router.rowkey || item.router.key] }, item.router.param || {});
// 在路由跳转前设置数据
this.$tool.store.set("routerData", param)
this.$router.push({
path: row[item.router.path] || item.router.path
});
return;
}
2023-12-27 05:46:43 +00:00
// 打开编辑层
else if (item.update && (item.update.url || item.update.name)) {
this.$emit('xtablehandleClick', row, Object.assign({ name: item.update.name || item.label, remoteurl: item.update.url || 'table/getUpdate?name=' + item.update.name }, item.update), 'update');
2024-01-05 11:03:07 +00:00
return;
}
// 统计
else if (item.stat && (item.stat.value || item.stat.key)) {
this.$emit('xtablehandleClick', row, item.stat, 'stat');
2023-12-27 05:46:43 +00:00
return;
}
// 打开表格
else if (item.table && (item.table.url || item.table.name)) {
this.$emit('xtablehandleClick', row, Object.assign({ name: item.table.name || item.label, remoteurl: item.table.url || 'table/get?name=' + item.table.name }, item.table), 'table');
2023-12-27 05:46:43 +00:00
return;
} else if (item.http && item.http.url && item.http.key && String(row[item.http.key])?.trim()) {
2023-09-05 07:23:52 +00:00
2024-01-09 04:42:47 +00:00
this.$confirm(item.http.tips || '确定要执行?', item.http.title || '提示', { type: item.http.type || 'warning' }).then(() => {
var param = Object.assign({}, { [item.http.key]: row[item.http.key] }, item.http.param || {});
2024-01-30 07:32:44 +00:00
this.$http.post(row[item.http.url] || item.http.url, param).then((res) => {
2023-12-27 05:46:43 +00:00
if (res.code == 200) {
this.$message.success(res.message || '操作成功')
2024-01-09 04:42:47 +00:00
// 刷新
this.$emit('xtablerefresh');
2023-12-27 05:46:43 +00:00
return;
}
this.$alert(res.message || '操作失败', "提示", { type: 'error' });
});
}).catch(() => {
2023-09-05 07:23:52 +00:00
2023-12-27 05:46:43 +00:00
})
}
},
getType(value) {
if (Array.isArray(value)) {
return value.length;
}
return value;
},
getNameByValue(value, degrees) {
const degree = degrees.find(degree => degree.value == value);
return degree ? (degree.name ? degree.name : degree.label) : value;
},
getImg(o) {
if (!o) {
return;
}
return typeof o === 'string' ? o : o.url;
},
2023-07-13 00:44:51 +00:00
}
2023-12-27 05:46:43 +00:00
}
2023-07-13 00:44:51 +00:00
</script>