新增-全界面弹出框组件
This commit is contained in:
@@ -95,6 +95,39 @@ const data = [
|
||||
'status': 1,
|
||||
'rolename': '操作员',
|
||||
},
|
||||
{
|
||||
'id': '448686878612127245',
|
||||
'username': 'operator_J',
|
||||
'password': '12345678',
|
||||
'realname': '孙芳2',
|
||||
'status': 1,
|
||||
'rolename': '操作员',
|
||||
},
|
||||
{
|
||||
'id': '448686878612127245',
|
||||
'username': 'operator_J',
|
||||
'password': '12345678',
|
||||
'realname': '孙芳2',
|
||||
'status': 1,
|
||||
'rolename': '操作员',
|
||||
},
|
||||
{
|
||||
'id': '448686878612127245',
|
||||
'username': 'operator_J',
|
||||
'password': '12345678',
|
||||
'realname': '孙芳2',
|
||||
'status': 1,
|
||||
'rolename': '操作员',
|
||||
},
|
||||
{
|
||||
'id': '448686878612127245',
|
||||
'username': 'operator_J',
|
||||
'password': '12345678',
|
||||
'realname': '孙芳2',
|
||||
'status': 1,
|
||||
'rolename': '操作员',
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
export default data
|
||||
@@ -1,38 +1,38 @@
|
||||
import { ref } from "vue";
|
||||
import { ref } from 'vue'
|
||||
|
||||
/**
|
||||
* @description 获取本地时间
|
||||
*/
|
||||
export const useTime = () => {
|
||||
const year = ref(0); // 年份
|
||||
const month = ref(0); // 月份
|
||||
const week = ref(""); // 星期几
|
||||
const day = ref(0); // 天数
|
||||
const hour = ref<number | string>(0); // 小时
|
||||
const minute = ref<number | string>(0); // 分钟
|
||||
const second = ref<number | string>(0); // 秒
|
||||
const nowTime = ref<string>(""); // 当前时间
|
||||
const year = ref(0) // 年份
|
||||
const month = ref(0) // 月份
|
||||
const week = ref('') // 星期几
|
||||
const day = ref(0) // 天数
|
||||
const hour = ref<number | string>(0) // 小时
|
||||
const minute = ref<number | string>(0) // 分钟
|
||||
const second = ref<number | string>(0) // 秒
|
||||
const nowTime = ref<string>('') // 当前时间
|
||||
|
||||
// 更新时间
|
||||
const updateTime = () => {
|
||||
const date = new Date();
|
||||
year.value = date.getFullYear();
|
||||
month.value = date.getMonth() + 1;
|
||||
week.value = "日一二三四五六".charAt(date.getDay());
|
||||
day.value = date.getDate();
|
||||
const date = new Date()
|
||||
year.value = date.getFullYear()
|
||||
month.value = date.getMonth() + 1
|
||||
week.value = '日一二三四五六'.charAt(date.getDay())
|
||||
day.value = date.getDate()
|
||||
hour.value =
|
||||
(date.getHours() + "")?.padStart(2, "0") ||
|
||||
new Intl.NumberFormat(undefined, { minimumIntegerDigits: 2 }).format(date.getHours());
|
||||
(date.getHours() + '')?.padStart(2, '0') ||
|
||||
new Intl.NumberFormat(undefined, { minimumIntegerDigits: 2 }).format(date.getHours())
|
||||
minute.value =
|
||||
(date.getMinutes() + "")?.padStart(2, "0") ||
|
||||
new Intl.NumberFormat(undefined, { minimumIntegerDigits: 2 }).format(date.getMinutes());
|
||||
(date.getMinutes() + '')?.padStart(2, '0') ||
|
||||
new Intl.NumberFormat(undefined, { minimumIntegerDigits: 2 }).format(date.getMinutes())
|
||||
second.value =
|
||||
(date.getSeconds() + "")?.padStart(2, "0") ||
|
||||
new Intl.NumberFormat(undefined, { minimumIntegerDigits: 2 }).format(date.getSeconds());
|
||||
nowTime.value = `${year.value}年${month.value}月${day.value} ${hour.value}:${minute.value}:${second.value}`;
|
||||
};
|
||||
(date.getSeconds() + '')?.padStart(2, '0') ||
|
||||
new Intl.NumberFormat(undefined, { minimumIntegerDigits: 2 }).format(date.getSeconds())
|
||||
nowTime.value = `${year.value}年${month.value}月${day.value} ${hour.value}:${minute.value}:${second.value}`
|
||||
}
|
||||
|
||||
updateTime();
|
||||
updateTime()
|
||||
|
||||
return { year, month, day, hour, minute, second, week, nowTime };
|
||||
};
|
||||
return { year, month, day, hour, minute, second, week, nowTime }
|
||||
}
|
||||
|
||||
37
frontend/src/hooks/useViewSize.ts
Normal file
37
frontend/src/hooks/useViewSize.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
export const useViewSize = () => {
|
||||
|
||||
const popupBaseView = ref(null)
|
||||
const viewWidth = ref("0")
|
||||
const viewHeight = ref("0")
|
||||
const unit = 'px'
|
||||
|
||||
/**
|
||||
* 更新宽和高的数据
|
||||
*/
|
||||
const updateDimensions = () => {
|
||||
if (popupBaseView.value) {
|
||||
viewWidth.value = popupBaseView.value.offsetWidth + unit
|
||||
viewHeight.value = popupBaseView.value.offsetHeight + unit
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 组件挂载完毕,计算宽高,并且给浏览器添加监听器,监听窗口大小改变
|
||||
*/
|
||||
onMounted(() => {
|
||||
updateDimensions()
|
||||
window.addEventListener('resize', updateDimensions)
|
||||
})
|
||||
|
||||
/**
|
||||
* 组件视图更新完毕,计算宽高
|
||||
*/
|
||||
onUpdated(() => {
|
||||
updateDimensions()
|
||||
})
|
||||
|
||||
return { popupBaseView, viewWidth, viewHeight }
|
||||
|
||||
}
|
||||
@@ -110,7 +110,7 @@
|
||||
margin-bottom: 10px;
|
||||
|
||||
.el-form {
|
||||
.el-form-item__content>* {
|
||||
.el-form-item__content > * {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@
|
||||
}
|
||||
|
||||
// 设置 el-table 中 header 文字不换行,并省略
|
||||
.el-table__header .el-table__cell>.cell {
|
||||
.el-table__header .el-table__cell > .cell {
|
||||
// white-space: nowrap;
|
||||
white-space: wrap;
|
||||
}
|
||||
@@ -328,6 +328,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
.el-overlay {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
|
||||
.el-dialog__body {
|
||||
// height: 200px;
|
||||
// max-height: 60vh;
|
||||
@@ -359,12 +364,13 @@
|
||||
|
||||
|
||||
.el-button {
|
||||
font-size: 12px ;
|
||||
font-size: 12px;
|
||||
|
||||
padding: 5px 11px;
|
||||
height: 24px;
|
||||
|
||||
}
|
||||
|
||||
.el-button + .el-button {
|
||||
margin-left: 10px;
|
||||
}
|
||||
@@ -434,18 +440,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-small{
|
||||
.el-dialog__body{
|
||||
|
||||
.dialog-small {
|
||||
.el-dialog__body {
|
||||
max-height: 260px;
|
||||
}
|
||||
}
|
||||
.dialog-middle{
|
||||
.el-dialog__body{
|
||||
|
||||
.dialog-middle {
|
||||
.el-dialog__body {
|
||||
max-height: 400px;
|
||||
}
|
||||
}
|
||||
.dialog-big{
|
||||
.el-dialog__body{
|
||||
|
||||
.dialog-big {
|
||||
.el-dialog__body {
|
||||
max-height: 620px;
|
||||
}
|
||||
}
|
||||
@@ -454,11 +463,14 @@
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
|
||||
.el-form-item {
|
||||
display: flex;
|
||||
width: 48%;
|
||||
|
||||
.el-form-item__content {
|
||||
flex: 1;
|
||||
|
||||
.el-select,
|
||||
.el-cascader,
|
||||
.el-input__inner,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class='table-box'>
|
||||
<div class='table-box' ref='popupBaseView'>
|
||||
<ProTable
|
||||
ref='proTable'
|
||||
:columns='columns'
|
||||
@@ -22,12 +22,13 @@
|
||||
</el-button>
|
||||
<el-button type='primary' link :icon='EditPen' @click="openDrawer('编辑', scope.row)">编辑</el-button>
|
||||
<el-button type='primary' link :icon='Refresh' @click='resetPass(scope.row)'>重置密码</el-button>
|
||||
<el-button type='primary' link :icon='Delete' @click='deleteAccount(scope.row)'>删除</el-button>
|
||||
<el-button type='primary' link :icon='CirclePlus' @click='deleteAccount()'>下钻</el-button>
|
||||
</template>
|
||||
</ProTable>
|
||||
</div>
|
||||
<single-column ref='singleColumn' />
|
||||
<double-column ref='doubleColumn' />
|
||||
<open :width='viewWidth' :height='viewHeight' ref='openView' />
|
||||
</template>
|
||||
<script setup lang='tsx' name='useProTable'>
|
||||
import { ref, reactive } from 'vue'
|
||||
@@ -42,24 +43,26 @@ import { CirclePlus, Delete, EditPen, Download, Upload, View, Refresh } from '@e
|
||||
import userDataList from '@/api/user/userData'
|
||||
import { useDictStore } from '@/stores/modules/dict'
|
||||
import SingleColumn from '@/views/demo/proTable/singleColumn.vue'
|
||||
import Open from '@/views/demo/proTable/Open.vue'
|
||||
import DoubleColumn from '@/views/demo/proTable/doubleColumn.vue'
|
||||
import { useViewSize } from '@/hooks/useViewSize'
|
||||
|
||||
const { popupBaseView, viewWidth, viewHeight } = useViewSize()
|
||||
|
||||
const dictStore = useDictStore()
|
||||
import {
|
||||
getUserList,
|
||||
deleteUser,
|
||||
changeUserStatus,
|
||||
resetUserPassWord,
|
||||
exportUserInfo,
|
||||
BatchAddUser,
|
||||
getUserStatus,
|
||||
} from '@/api/user/user'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import router from '@/routers'
|
||||
|
||||
const userData = userDataList
|
||||
const singleColumn = ref()
|
||||
const doubleColumn = ref()
|
||||
const openView = ref()
|
||||
// ProTable 实例
|
||||
const proTable = ref<ProTableInstance>()
|
||||
// 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
|
||||
@@ -117,7 +120,7 @@ const columns = reactive<ColumnProps<User.ResUserList>[]>([
|
||||
},
|
||||
},
|
||||
},
|
||||
{ prop: 'idCard', label: '身份证号', search: { el: 'input' } },
|
||||
{ prop: 'idCard', label: '身份证号' },
|
||||
{ prop: 'email', label: '邮箱' },
|
||||
{ prop: 'address', label: '居住地址', width: 120 },
|
||||
{
|
||||
@@ -157,11 +160,11 @@ const columns = reactive<ColumnProps<User.ResUserList>[]>([
|
||||
},
|
||||
{ prop: 'operation', label: '操作', fixed: 'right', width: 330 },
|
||||
])
|
||||
// 删除用户信息
|
||||
const deleteAccount = async (params: User.ResUserList) => {
|
||||
// await useHandleData(deleteUser, { id: [params.id] }, `删除【${params.username}】用户`)
|
||||
// proTable.value?.getTableList()
|
||||
router.push('/plan/autoTest')
|
||||
|
||||
|
||||
// 下钻
|
||||
const deleteAccount = async () => {
|
||||
openView.value.open('测试弹出框')
|
||||
}
|
||||
// 批量删除用户信息
|
||||
const batchDelete = async (id: string[]) => {
|
||||
|
||||
177
frontend/src/views/demo/proTable/open.vue
Normal file
177
frontend/src/views/demo/proTable/open.vue
Normal file
@@ -0,0 +1,177 @@
|
||||
<!--单列-->
|
||||
<template>
|
||||
<el-dialog class='table-box'
|
||||
v-model='dialogVisible'
|
||||
top='114px'
|
||||
:style="{height:height,maxHeight:height,overflow:'hidden'}"
|
||||
:title='title'
|
||||
:width='width'
|
||||
:modal='false'>
|
||||
<div class='table-box'>
|
||||
<ProTable
|
||||
ref='proTable'
|
||||
:columns='columns'
|
||||
:data='userData'
|
||||
>
|
||||
<!-- 表格 header 按钮 -->
|
||||
<template #tableHeader='scope'>
|
||||
<el-button type='primary' :icon='CirclePlus' @click="openDrawer('新增')">新增用户</el-button>
|
||||
</template>
|
||||
<!-- 表格操作 -->
|
||||
<template #operation='scope'>
|
||||
<el-button type='primary' link :icon='View'
|
||||
@click="openDrawer('查看', scope.row)">查看
|
||||
</el-button>
|
||||
<el-button type='primary' link :icon='EditPen' @click="openDrawer('编辑', scope.row)">编辑</el-button>
|
||||
<el-button type='primary' link :icon='Refresh' @click='resetPass(scope.row)'>重置密码</el-button>
|
||||
<el-button type='primary' link :icon='Delete' @click='deleteAccount(scope.row)'>删除</el-button>
|
||||
</template>
|
||||
</ProTable>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script setup lang='tsx'>
|
||||
import { CirclePlus, Delete, EditPen, Refresh, View } from '@element-plus/icons-vue'
|
||||
import ProTable from '@/components/ProTable/index.vue'
|
||||
import { useHandleData } from '@/hooks/useHandleData'
|
||||
import { useAuthButtons } from '@/hooks/useAuthButtons'
|
||||
import { reactive } from 'vue'
|
||||
import { ColumnProps } from '@/components/ProTable/interface'
|
||||
import { User } from '@/api/user/interface'
|
||||
import { useDictStore } from '@/stores/modules/dict'
|
||||
|
||||
const dictStore = useDictStore()
|
||||
import {
|
||||
changeUserStatus,
|
||||
} from '@/api/user/user'
|
||||
import userDataList from '@/api/user/userData'
|
||||
|
||||
const userData = userDataList
|
||||
const proTable = ref()
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const title = ref('单列弹出框')
|
||||
|
||||
const { BUTTONS } = useAuthButtons()
|
||||
// 表格配置项
|
||||
const columns = reactive<ColumnProps<User.ResUserList>[]>([
|
||||
{ type: 'selection', fixed: 'left', width: 70 },
|
||||
{ type: 'index', fixed: 'left', width: 70, label: '序号' },
|
||||
{
|
||||
prop: 'username',
|
||||
label: '姓名',
|
||||
width: 120,
|
||||
search: { el: 'input' },
|
||||
},
|
||||
{
|
||||
prop: 'gender',
|
||||
label: '性别',
|
||||
// 字典数据(本地数据)
|
||||
enum: dictStore.getDictData('sex'),
|
||||
search: { el: 'select', props: { filterable: true } },
|
||||
fieldNames: { label: 'label', value: 'code' },
|
||||
},
|
||||
{
|
||||
prop: 'age',
|
||||
label: '年龄',
|
||||
search: {
|
||||
// 自定义 search 显示内容
|
||||
render: ({ searchParam }) => {
|
||||
return (
|
||||
<div class='flx-center'>
|
||||
<el-input vModel_trim={searchParam.minAge} placeholder='最小年龄' />
|
||||
<span class='mr10 ml10'>-</span>
|
||||
<el-input vModel_trim={searchParam.maxAge} placeholder='最大年龄' />
|
||||
</div>
|
||||
)
|
||||
},
|
||||
},
|
||||
},
|
||||
{ prop: 'idCard', label: '身份证号', search: { el: 'input' } },
|
||||
{ prop: 'email', label: '邮箱' },
|
||||
{ prop: 'address', label: '居住地址', width: 120 },
|
||||
{
|
||||
prop: 'status',
|
||||
label: '状态',
|
||||
enum: dictStore.getDictData('status'),
|
||||
search: { el: 'tree-select', props: { filterable: true } },
|
||||
fieldNames: { label: 'userLabel', value: 'userStatus' },
|
||||
render: scope => {
|
||||
return (
|
||||
<>
|
||||
{BUTTONS.value.status ? (
|
||||
<el-switch
|
||||
model-value={scope.row.status}
|
||||
active-text={scope.row.status ? '启用' : '禁用'}
|
||||
active-value={1}
|
||||
inactive-value={0}
|
||||
onClick={() => changeStatus(scope.row)}
|
||||
/>
|
||||
) : (
|
||||
<el-tag type={scope.row.status ? 'success' : 'danger'}>{scope.row.status ? '启用' : '禁用'}</el-tag>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
prop: 'createTime',
|
||||
label: '创建时间',
|
||||
width: 180,
|
||||
search: {
|
||||
el: 'date-picker',
|
||||
span: 1,
|
||||
props: { type: 'daterange', valueFormat: 'YYYY-MM-DD' },
|
||||
defaultValue: ['2024-11-12', '2024-12-12'],
|
||||
},
|
||||
},
|
||||
{ prop: 'operation', label: '操作', fixed: 'right', width: 330 },
|
||||
])
|
||||
|
||||
|
||||
const open = (textTitle: string) => {
|
||||
dialogVisible.value = true
|
||||
title.value = textTitle
|
||||
}
|
||||
|
||||
|
||||
defineExpose({ open })
|
||||
|
||||
|
||||
const props = defineProps({
|
||||
width: {
|
||||
type: String,
|
||||
default: '800px',
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: '744px',
|
||||
},
|
||||
})
|
||||
|
||||
// 切换用户状态
|
||||
const changeStatus = async (row: User.ResUserList) => {
|
||||
await useHandleData(changeUserStatus, {
|
||||
id: row.id,
|
||||
status: row.status == 1 ? 0 : 1,
|
||||
}, `切换【${row.username}】用户状态`)
|
||||
proTable.value?.getTableList()
|
||||
}
|
||||
|
||||
// 删除用户信息
|
||||
const deleteAccount = async (params: User.ResUserList) => {
|
||||
|
||||
}
|
||||
// 重置用户密码
|
||||
const resetPass = async (params: User.ResUserList) => {
|
||||
|
||||
}
|
||||
|
||||
// 打开 drawer(新增、查看、编辑)
|
||||
const openDrawer = (title: string, row: Partial<User.ResUserList> = {}) => {
|
||||
}
|
||||
|
||||
</script>
|
||||
<style>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user