提交 5a8c5913 编写于 作者: 刘英杰's avatar 刘英杰

保存

上级 aa2f1a09
// Please install OpenAI SDK first: `npm install openai`
import OpenAI from "openai";
//express_demo.js 文件
import express from 'express'
const openai = new OpenAI({
baseURL: 'https://api.deepseek.com',
apiKey: 'sk-6d4008c952ff48509e693df56b9c1520'
});
var app = express();
app.get('/openAiApi', function (req, res) {
async function main() {
const completion = await openai.chat.completions.create({
messages: [{ role: "system", content: req.query.param},],
model: "deepseek-reasoner",
});
// console.log(completion.choices[0].message.content);
res.send(JSON.stringify({code:1,msg:'成功',response:{content:completion.choices[0].message.content}}));
}
main();
})
var server = app.listen(9999, function () {
var host = server.address().address
var port = server.address().port
console.log("应用实例,访问地址为 http://%s:%s", host, port)
})
\ No newline at end of file
此差异已折叠。
<template>
<!-- 通用Table -->
<div>
<Table
:border="tableBorder"
class="ivu-mt"
:columns="tableColumns"
:data="tableData"
:loading="tableLoading"
:size="tableSize"
>
<template slot-scope="{ row, index }" slot="generalSwitch">
<Switch
v-model="row.is_enable"
size="large"
:true-value="1"
:false-value="0"
@on-change="(val) => switchChange(val, row, index)">
<span type="md-checkmark" slot="open" >启用</span>
<span type="md-close" slot="close">停用</span>
</Switch>
</template>
<template slot-scope="{ row }" slot="action">
<Button type="info" size="small" @click="edit(row)">编辑</Button>
<Poptip confirm transfer title="是否确认删除?" @on-ok="del(row)">
<Button type="error" size="small" style="margin-left: 8px">删除</Button>
</Poptip>
</template>
<template slot-scope="{ row }" slot="actionAndDetails">
<a @click="details(row)">详情</a>
<Button type="info" size="small" @click="edit(row)" style="margin-left: 8px">编辑</Button>
<Poptip confirm transfer title="是否确认删除?" @on-ok="del(row)">
<Button type="error" size="small" style="margin-left: 8px">删除</Button>
</Poptip>
</template>
<!-- 自定义插槽 -->
<template v-for="(_, slot) in $scopedSlots" v-slot:[slot]="scope">
<slot :name="slot" v-bind="scope"> </slot>
</template>
</Table>
<div class="ivu-text-center ivu-mt">
<Page
:total="dataCount"
:current="pageIndex"
:page-size="pageSize"
:page-size-opts="pageSizeOpts"
show-total
show-sizer
@on-change="handleChangePage"
@on-page-size-change="handleChangePageSize"
/>
</div>
</div>
</template>
<script>
export default {
props: {
tableBorder: { type: Boolean, default: false},
tableColumns: { type: Array, require: true },
tableData: { type: Array, require: true },
tableLoading: { type: Boolean, default: false },
tableSize: { type: String, default: 'default' },
dataCount: { type: Number, require: true },
pageIndex: { type: Number, require: true },
pageSize: { type: Number, require: true },
pageSizeOpts: { type: Array, default: () => [10, 20, 50, 100] },
},
data() {
return {}
},
computed: {},
created() {},
mounted() {},
methods: {
// 改变开关
switchChange(val, row, index) {
this.$emit('switchChange', val, row, index)
},
// 详情
details(row) {
this.$emit('rowDetails', row)
},
// 编辑行
edit(row) {
this.$emit('rowEdit', row)
},
// 删除行
del(row) {
this.$emit('rowDelete', row)
},
// 翻页
handleChangePage(val) {
this.$emit('onPageChange', val)
},
// 更改每页长度
handleChangePageSize(val) {
this.$emit('onPageSizeChange', val)
},
},
}
</script>
<style scoped lang="less">
</style>
<template>
<!-- 通用搜索表单 -->
<div>
<Form
class="searchDiv"
:model="searchCondObj"
:label-width="labelWidth"
:label-colon="labelColon">
<Row>
<Col v-bind="grid" v-for="item in searchCondList.filter(a => a.show)" :key="item.id">
<FormItem :label="item.name">
<Input
v-if="item.type == 'input'"
style="width: 100%;"
v-model="searchCondObj[item.id]"
clearable
:placeholder="'请输入'+item.name"></Input>
<Select
v-else-if="item.type == 'select'"
style="width: 100%;"
v-model="searchCondObj[item.id]"
clearable
:placeholder="'请选择'+item.name"
>
<Option
v-for="it in item.optList"
:key="it.value"
:value="it.value">{{ it.label }}</Option>
</Select>
<DatePicker
v-else-if="item.type == 'datetime'"
v-model="searchCondObj[item['id']]"
type="datetime"
format="yyyy-MM-dd HH:mm"
:placeholder="'请选择'+item.name"
@on-change="(val1, val2) => datetimeChange(val1, val2, item.id)"/>
</FormItem>
</Col>
<Col v-bind="grid" class="buttonCol">
<Button type="primary" @click="searchBt">查询</Button>
<Button @click="resetBt">重置</Button>
</Col>
</Row>
</Form>
</div>
</template>
<script>
export default {
props: {
// 搜索项列表
searchCondList: { type: Array, require: true },
// label宽度
labelWidth: { type: Number, default: 100 },
// label冒号
labelColon: { type: Boolean, default: true },
},
data() {
return {
// 搜索条件布局
grid: {
sm: 12,
md: 12,
lg: 8,
xl: 6,
},
// 搜索数据
searchCondObj: {},
}
},
computed: {},
created() {},
mounted() {},
methods: {
// 搜索
searchBt() {
this.$emit('onSubmit', this.searchCondObj)
},
// 重置
resetBt() {
// console.log('重置按钮')
this.searchCondObj = {}
this.$emit('onReset')
},
// 日期时间改变选择
datetimeChange(val1, val2, id) {
// console.log('日期时间改变选择', val1, val2, id)
this.searchCondObj[id] = val1
},
},
}
</script>
<style scoped lang="less">
.searchDiv{
.ivu-form-item{
margin-bottom: 12px;
}
.buttonCol{
margin-left: auto;
text-align: right;
.ivu-btn{
margin-left: 8px;
}
}
}
</style>
<template>
<div style="width: 100%;height: 100%;">
<!-- 右侧人员列表 -->
<div class="role-content">
<Tabs style="width: 100%;" type="card" @on-click="tabsChange">
<TabPane label="申请耗材" style="width: 100%;height: 100%;">
</TabPane>
<TabPane label="借用记录" style="height: 100%;width: 100%;">
</TabPane>
</Tabs>
<component v-if="init.tabsChange== 0" :is="ApplyFor"></component>
<component v-else :is="TakeOver"></component>
</div>
</div>
</template>
<script setup>
const ApplyFor = defineAsyncComponent(()=>import('@/pages/applicationClaim/consumables/components/applyFor.vue'))
const TakeOver = defineAsyncComponent(()=>import('@/pages/applicationClaim/consumables/components/takeOver.vue'))
import {ref, onMounted, reactive, computed, defineAsyncComponent} from 'vue'
import {Message, Modal as ModalConfirm} from 'view-ui-plus'
import {
RoleInit,
PermissonList,
PermissonAdd,
PermissonDelete,
SelectTeacher,
GetDepts
} from '@/api/api'
const init = reactive({
tabsChange: 0
})
// 角色列表
const roleList = ref([
{
"role_type": 0,
"role_name": "设备审核",
"count": 14
},
{
"role_type": 1,
"role_name": "耗材审核",
"count": 4
},
])
function tabsChange(e){
console.log("🚀🚀🚀,",e)
init.tabsChange = e
}
// 部门列表
const departmentOptions = ref([])
// 当前选中的角色
const currentRole = ref({})
// 获取角色图标
const getRoleIcon = (roleType) => {
switch (roleType) {
case 0:
return 'md-settings'
case 1:
return 'md-people'
case 2:
return 'md-person'
case 3:
return 'md-briefcase'
default:
return 'md-person'
}
}
// 获取角色图标样式类
const getRoleIconClass = (roleType) => {
switch (roleType) {
case 0:
return 'role-admin'
case 1:
return 'role-party-office'
case 2:
return 'role-responsible-dept'
case 3:
return 'role-entrance-dept'
default:
return 'role-admin'
}
}
// 用户表格列定义
const userColumns = computed(() => {
const columns = [
{
title: '#',
type: 'index',
width: 60
},
{
title: '照片',
slot: 'avatar',
width: 80
},
{
title: '工号',
key: 'user_id',
width: 120
},
{
title: '姓名',
key: 'name',
minWidth: 120
},
]
// 当角色为部门负责人时(role_type === 2),添加负责部门列
if (currentRole.value.role_type === 2) {
columns.push({
title: '负责部门',
slot: 'duty_depts',
minWidth: 200
})
}
// 添加操作列
columns.push({
title: '操作',
slot: 'action',
width: 80,
align: 'center'
})
return columns
})
// 可添加用户表格列定义
const availableUserColumns = ref([
{
title: '照片',
slot: 'avatar',
width: 80
},
{
title: '工号',
key: 'user_id',
width: 120
},
{
title: '姓名',
key: 'name',
minWidth: 120
},
{
title: '部门',
key: 'dept_name',
minWidth: 150
},
{
title: '操作',
slot: 'action',
width: 80,
align: 'center'
}
])
// 分页相关变量
const total = ref(0)
const pageIndex = ref(1)
const pageSize = ref(20)
// 搜索关键词
const searchKeyword = ref('')
// 加载状态
const loading = ref(false)
// 添加用户对话框
const addUserModal = reactive({
show: false,
loading: false,
keyword: '',
userList: [],
dutyDepts: []
})
// 用户列表
const userList = ref([])
// 加载角色列表
const loadRoleList = async () => {
try {
await RoleInit().then(res => {
// roleList.value = res.response
if (res.response.length > 0 && !currentRole.value.role_type && currentRole.value.role_type !== 0) {
currentRole.value = res.response[0]
loadRoleUsers()
}
}).catch(error => {
console.error('获取角色列表失败:', error)
Message.error('获取角色列表失败')
})
} catch (error) {
console.error('获取角色列表失败:', error)
Message.error('获取角色列表失败')
}
}
// 加载角色用户
const loadRoleUsers = async () => {
if (!currentRole.value && currentRole.value.role_type === undefined) return
loading.value = true
try {
const params = {
role_type: currentRole.value.role_type,
query: searchKeyword.value
}
await PermissonList(params).then(res => {
userList.value = res.response || []
total.value = res.response ? res.response.length : 0
}).catch(error => {
console.error('获取角色用户列表失败:', error)
Message.error('获取角色用户列表失败')
}).finally(() => {
loading.value = false
})
} catch (error) {
console.error('获取角色用户列表失败:', error)
Message.error('获取角色用户列表失败')
loading.value = false
}
}
// 选择角色
const handleSelectRole = (role) => {
currentRole.value = role
searchKeyword.value = ''
pageIndex.value = 1
loadRoleUsers()
}
// 搜索用户
const handleSearch = () => {
pageIndex.value = 1
loadRoleUsers()
}
// 分页改变
const handlePageChange = (page) => {
pageIndex.value = page
}
// 页大小改变
const handlePageSizeChange = (size) => {
pageSize.value = size
pageIndex.value = 1
}
// 添加用户
const handleAddUser = () => {
addUserModal.keyword = ''
addUserModal.userList = []
addUserModal.dutyDepts = []
addUserModal.show = true
searchAvailableUsers()
}
// 搜索可添加的用户
const searchAvailableUsers = async () => {
addUserModal.loading = true
try {
const params = {
query: addUserModal.keyword
}
await SelectTeacher(params).then(res => {
addUserModal.userList = res.response || []
}).catch(error => {
console.error('搜索用户失败:', error)
Message.error('搜索用户失败')
}).finally(() => {
addUserModal.loading = false
})
} catch (error) {
console.error('搜索用户失败:', error)
Message.error('搜索用户失败')
addUserModal.loading = false
}
}
// 加载部门列表
const loadDepartments = async () => {
try {
await GetDepts().then((res) => {
departmentOptions.value = res.response.map(dept => ({
value: dept.dept_id,
label: dept.dept_name
}))
}).catch(error => {
console.error('获取部门数据失败:', error)
Message.error('获取部门数据失败')
})
} catch (error) {
console.error('获取部门数据失败:', error)
Message.error('获取部门数据失败')
}
}
onMounted(() => {
loadRoleList()
loadDepartments()
})
</script>
<style scoped>
.role-container {
display: flex;
min-height: calc(100vh - 150px);
/* border: 1px solid #e8eaec; */
border-radius: 4px;
overflow: auto;
gap: 16px;
}
.role-sidebar {
width: 300px;
border-right: 1px solid #e8eaec;
background-color: #fff;
overflow-y: auto;
height: 200px;
}
.role-title {
padding: 16px;
font-size: 16px;
font-weight: bold;
border-bottom: 1px solid #e8eaec;
}
.role-list {
padding: 10px 0;
}
.role-item {
display: flex;
align-items: center;
padding: 12px 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.role-item:hover {
background-color: #f0f0f0;
}
.role-item.active {
background-color: #e8f7ff;
color: #2d8cf0;
}
.role-item-icon {
width: 36px;
height: 36px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-right: 12px;
color: #fff;
}
.role-admin {
background-color: #2d8cf0;
}
.role-party-office {
background-color: #19be6b;
}
.role-entrance-dept {
background-color: #ff9900;
}
.role-responsible-dept {
background-color: #ed4014;
}
.role-item-info {
flex: 1;
}
.role-name {
font-size: 14px;
margin-bottom: 4px;
}
.role-count {
font-size: 12px;
color: #808695;
}
.role-content {
display: flex;
flex-direction: column;
gap: 16px;
flex: 1;
}
.role-toolbar {
height: 100%;
display: flex;
justify-content: space-between;
/* margin-bottom: 16px; */
position: sticky;
top: 0;
background-color: #fff;
z-index: 1;
}
.search-box {
width: 280px;
}
.pagination {
/* margin-top: 16px; */
text-align: center;
position: sticky;
bottom: 0;
background-color: #fff;
z-index: 1;
}
.action-btns {
display: flex;
justify-content: center;
}
.user-avatar {
display: flex;
justify-content: center;
align-items: center;
}
.user-avatar img {
width: 100%;
height: 100%;
object-fit: cover;
}
.add-user-search {
margin-bottom: 16px;
}
.duty-dept-select {
margin-bottom: 16px;
}
</style>
\ No newline at end of file
<template>
<div style="width: 100%;height: 100%;">
<!-- 右侧人员列表 -->
<div class="role-content">
<Tabs style="width: 100%;" type="card" @on-click="tabsChange">
<TabPane label="申请设备" style="width: 100%;height: 100%;">
</TabPane>
<TabPane label="借用记录" style="height: 100%;width: 100%;">
</TabPane>
</Tabs>
<component v-if="init.tabsChange== 0" :is="ApplyFor"></component>
<component v-else :is="TakeOver"></component>
</div>
</div>
</template>
<script setup>
const ApplyFor = defineAsyncComponent(()=>import('@/pages/applicationClaim/device/components/applyFor.vue'))
const TakeOver = defineAsyncComponent(()=>import('@/pages/applicationClaim/device/components/takeOver.vue'))
import {ref, onMounted, reactive, computed, defineAsyncComponent} from 'vue'
import {Message, Modal as ModalConfirm} from 'view-ui-plus'
import {
RoleInit,
PermissonList,
PermissonAdd,
PermissonDelete,
SelectTeacher,
GetDepts
} from '@/api/api'
const init = reactive({
tabsChange: 0
})
// 角色列表
const roleList = ref([
{
"role_type": 0,
"role_name": "设备审核",
"count": 14
},
{
"role_type": 1,
"role_name": "耗材审核",
"count": 4
},
])
function tabsChange(e){
console.log("🚀🚀🚀,",e)
init.tabsChange = e
}
// 部门列表
const departmentOptions = ref([])
// 当前选中的角色
const currentRole = ref({})
// 获取角色图标
const getRoleIcon = (roleType) => {
switch (roleType) {
case 0:
return 'md-settings'
case 1:
return 'md-people'
case 2:
return 'md-person'
case 3:
return 'md-briefcase'
default:
return 'md-person'
}
}
// 获取角色图标样式类
const getRoleIconClass = (roleType) => {
switch (roleType) {
case 0:
return 'role-admin'
case 1:
return 'role-party-office'
case 2:
return 'role-responsible-dept'
case 3:
return 'role-entrance-dept'
default:
return 'role-admin'
}
}
// 用户表格列定义
const userColumns = computed(() => {
const columns = [
{
title: '#',
type: 'index',
width: 60
},
{
title: '照片',
slot: 'avatar',
width: 80
},
{
title: '工号',
key: 'user_id',
width: 120
},
{
title: '姓名',
key: 'name',
minWidth: 120
},
]
// 当角色为部门负责人时(role_type === 2),添加负责部门列
if (currentRole.value.role_type === 2) {
columns.push({
title: '负责部门',
slot: 'duty_depts',
minWidth: 200
})
}
// 添加操作列
columns.push({
title: '操作',
slot: 'action',
width: 80,
align: 'center'
})
return columns
})
// 可添加用户表格列定义
const availableUserColumns = ref([
{
title: '照片',
slot: 'avatar',
width: 80
},
{
title: '工号',
key: 'user_id',
width: 120
},
{
title: '姓名',
key: 'name',
minWidth: 120
},
{
title: '部门',
key: 'dept_name',
minWidth: 150
},
{
title: '操作',
slot: 'action',
width: 80,
align: 'center'
}
])
// 分页相关变量
const total = ref(0)
const pageIndex = ref(1)
const pageSize = ref(20)
// 搜索关键词
const searchKeyword = ref('')
// 加载状态
const loading = ref(false)
// 添加用户对话框
const addUserModal = reactive({
show: false,
loading: false,
keyword: '',
userList: [],
dutyDepts: []
})
// 用户列表
const userList = ref([])
// 加载角色列表
const loadRoleList = async () => {
try {
await RoleInit().then(res => {
// roleList.value = res.response
if (res.response.length > 0 && !currentRole.value.role_type && currentRole.value.role_type !== 0) {
currentRole.value = res.response[0]
loadRoleUsers()
}
}).catch(error => {
console.error('获取角色列表失败:', error)
Message.error('获取角色列表失败')
})
} catch (error) {
console.error('获取角色列表失败:', error)
Message.error('获取角色列表失败')
}
}
// 加载角色用户
const loadRoleUsers = async () => {
if (!currentRole.value && currentRole.value.role_type === undefined) return
loading.value = true
try {
const params = {
role_type: currentRole.value.role_type,
query: searchKeyword.value
}
await PermissonList(params).then(res => {
userList.value = res.response || []
total.value = res.response ? res.response.length : 0
}).catch(error => {
console.error('获取角色用户列表失败:', error)
Message.error('获取角色用户列表失败')
}).finally(() => {
loading.value = false
})
} catch (error) {
console.error('获取角色用户列表失败:', error)
Message.error('获取角色用户列表失败')
loading.value = false
}
}
// 选择角色
const handleSelectRole = (role) => {
currentRole.value = role
searchKeyword.value = ''
pageIndex.value = 1
loadRoleUsers()
}
// 搜索用户
const handleSearch = () => {
pageIndex.value = 1
loadRoleUsers()
}
// 分页改变
const handlePageChange = (page) => {
pageIndex.value = page
}
// 页大小改变
const handlePageSizeChange = (size) => {
pageSize.value = size
pageIndex.value = 1
}
// 添加用户
const handleAddUser = () => {
addUserModal.keyword = ''
addUserModal.userList = []
addUserModal.dutyDepts = []
addUserModal.show = true
searchAvailableUsers()
}
// 搜索可添加的用户
const searchAvailableUsers = async () => {
addUserModal.loading = true
try {
const params = {
query: addUserModal.keyword
}
await SelectTeacher(params).then(res => {
addUserModal.userList = res.response || []
}).catch(error => {
console.error('搜索用户失败:', error)
Message.error('搜索用户失败')
}).finally(() => {
addUserModal.loading = false
})
} catch (error) {
console.error('搜索用户失败:', error)
Message.error('搜索用户失败')
addUserModal.loading = false
}
}
// 加载部门列表
const loadDepartments = async () => {
try {
await GetDepts().then((res) => {
departmentOptions.value = res.response.map(dept => ({
value: dept.dept_id,
label: dept.dept_name
}))
}).catch(error => {
console.error('获取部门数据失败:', error)
Message.error('获取部门数据失败')
})
} catch (error) {
console.error('获取部门数据失败:', error)
Message.error('获取部门数据失败')
}
}
onMounted(() => {
loadRoleList()
loadDepartments()
})
</script>
<style scoped>
.role-container {
display: flex;
min-height: calc(100vh - 150px);
/* border: 1px solid #e8eaec; */
border-radius: 4px;
overflow: auto;
gap: 16px;
}
.role-sidebar {
width: 300px;
border-right: 1px solid #e8eaec;
background-color: #fff;
overflow-y: auto;
height: 200px;
}
.role-title {
padding: 16px;
font-size: 16px;
font-weight: bold;
border-bottom: 1px solid #e8eaec;
}
.role-list {
padding: 10px 0;
}
.role-item {
display: flex;
align-items: center;
padding: 12px 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.role-item:hover {
background-color: #f0f0f0;
}
.role-item.active {
background-color: #e8f7ff;
color: #2d8cf0;
}
.role-item-icon {
width: 36px;
height: 36px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-right: 12px;
color: #fff;
}
.role-admin {
background-color: #2d8cf0;
}
.role-party-office {
background-color: #19be6b;
}
.role-entrance-dept {
background-color: #ff9900;
}
.role-responsible-dept {
background-color: #ed4014;
}
.role-item-info {
flex: 1;
}
.role-name {
font-size: 14px;
margin-bottom: 4px;
}
.role-count {
font-size: 12px;
color: #808695;
}
.role-content {
display: flex;
flex-direction: column;
gap: 16px;
flex: 1;
}
.role-toolbar {
height: 100%;
display: flex;
justify-content: space-between;
/* margin-bottom: 16px; */
position: sticky;
top: 0;
background-color: #fff;
z-index: 1;
}
.search-box {
width: 280px;
}
.pagination {
/* margin-top: 16px; */
text-align: center;
position: sticky;
bottom: 0;
background-color: #fff;
z-index: 1;
}
.action-btns {
display: flex;
justify-content: center;
}
.user-avatar {
display: flex;
justify-content: center;
align-items: center;
}
.user-avatar img {
width: 100%;
height: 100%;
object-fit: cover;
}
.add-user-search {
margin-bottom: 16px;
}
.duty-dept-select {
margin-bottom: 16px;
}
</style>
\ No newline at end of file
<template>
<div class="role-container">
<!-- 左侧角色列表 -->
<div class="role-sidebar">
<div class="role-title">申请申领</div>
<div class="role-list">
<div
v-for="role in roleList"
:key="role.role_type"
:class="['role-item', { active: currentRole.role_type === role.role_type }]"
@click="handleSelectRole(role)"
>
<div class="role-item-icon" :class="getRoleIconClass(role.role_type)">
<Icon :type="role.role_type === 0 ? 'ios-desktop' : 'ios-cube'"/>
</div>
<div class="role-item-info">
<div class="role-name">{{ role.role_name }}</div>
</div>
</div>
</div>
</div>
<Card dis-hover :bordered="false" style="width: calc(100% - 300px);height: 100%;">
<!-- 右侧人员列表 -->
<component :is="currentRole.role_type == 0 ? Devices : Consumables"></component>
</Card>
</div>
</template>
<script setup>
const Devices = defineAsyncComponent(()=>import('@/pages/applicationClaim/device'))
const Consumables = defineAsyncComponent(()=>import('@/pages/applicationClaim/consumables'))
import {ref, onMounted, reactive, computed, defineAsyncComponent} from 'vue'
import {Message, Modal as ModalConfirm} from 'view-ui-plus'
import {
RoleInit,
PermissonList,
PermissonAdd,
PermissonDelete,
SelectTeacher,
GetDepts
} from '@/api/api'
// 角色列表
const roleList = ref([
{
"role_type": 0,
"role_name": "设备审核",
"count": 14
},
{
"role_type": 1,
"role_name": "耗材审核",
"count": 4
},
])
// 部门列表
const departmentOptions = ref([])
// 当前选中的角色
const currentRole = ref({role_type:0})
// 获取角色图标
const getRoleIcon = (roleType) => {
switch (roleType) {
case 0:
return 'md-settings'
case 1:
return 'md-people'
case 2:
return 'md-person'
case 3:
return 'md-briefcase'
default:
return 'md-person'
}
}
// 获取角色图标样式类
const getRoleIconClass = (roleType) => {
switch (roleType) {
case 0:
return 'role-admin'
case 1:
return 'role-party-office'
case 2:
return 'role-responsible-dept'
case 3:
return 'role-entrance-dept'
default:
return 'role-admin'
}
}
// 用户表格列定义
const userColumns = computed(() => {
const columns = [
{
title: '#',
type: 'index',
width: 60
},
{
title: '照片',
slot: 'avatar',
width: 80
},
{
title: '工号',
key: 'user_id',
width: 120
},
{
title: '姓名',
key: 'name',
minWidth: 120
},
]
// 当角色为部门负责人时(role_type === 2),添加负责部门列
if (currentRole.value.role_type === 2) {
columns.push({
title: '负责部门',
slot: 'duty_depts',
minWidth: 200
})
}
// 添加操作列
columns.push({
title: '操作',
slot: 'action',
width: 80,
align: 'center'
})
return columns
})
// 可添加用户表格列定义
const availableUserColumns = ref([
{
title: '照片',
slot: 'avatar',
width: 80
},
{
title: '工号',
key: 'user_id',
width: 120
},
{
title: '姓名',
key: 'name',
minWidth: 120
},
{
title: '部门',
key: 'dept_name',
minWidth: 150
},
{
title: '操作',
slot: 'action',
width: 80,
align: 'center'
}
])
// 分页相关变量
const total = ref(0)
const pageIndex = ref(1)
const pageSize = ref(20)
// 搜索关键词
const searchKeyword = ref('')
// 加载状态
const loading = ref(false)
// 添加用户对话框
const addUserModal = reactive({
show: false,
loading: false,
keyword: '',
userList: [],
dutyDepts: []
})
// 用户列表
const userList = ref([])
// 加载角色列表
const loadRoleList = async () => {
try {
await RoleInit().then(res => {
// roleList.value = res.response
if (res.response.length > 0 && !currentRole.value.role_type && currentRole.value.role_type !== 0) {
currentRole.value = res.response[0]
loadRoleUsers()
}
}).catch(error => {
console.error('获取角色列表失败:', error)
Message.error('获取角色列表失败')
})
} catch (error) {
console.error('获取角色列表失败:', error)
Message.error('获取角色列表失败')
}
}
// 加载角色用户
const loadRoleUsers = async () => {
if (!currentRole.value && currentRole.value.role_type === undefined) return
loading.value = true
try {
const params = {
role_type: currentRole.value.role_type,
query: searchKeyword.value
}
await PermissonList(params).then(res => {
userList.value = res.response || []
total.value = res.response ? res.response.length : 0
}).catch(error => {
console.error('获取角色用户列表失败:', error)
Message.error('获取角色用户列表失败')
}).finally(() => {
loading.value = false
})
} catch (error) {
console.error('获取角色用户列表失败:', error)
Message.error('获取角色用户列表失败')
loading.value = false
}
}
// 选择角色
const handleSelectRole = (role) => {
console.log("role🚀🚀🚀,",role)
currentRole.value = role
searchKeyword.value = ''
pageIndex.value = 1
loadRoleUsers()
}
// 搜索用户
const handleSearch = () => {
pageIndex.value = 1
loadRoleUsers()
}
// 分页改变
const handlePageChange = (page) => {
pageIndex.value = page
}
// 页大小改变
const handlePageSizeChange = (size) => {
pageSize.value = size
pageIndex.value = 1
}
// 添加用户
const handleAddUser = () => {
addUserModal.keyword = ''
addUserModal.userList = []
addUserModal.dutyDepts = []
addUserModal.show = true
searchAvailableUsers()
}
// 搜索可添加的用户
const searchAvailableUsers = async () => {
addUserModal.loading = true
try {
const params = {
query: addUserModal.keyword
}
await SelectTeacher(params).then(res => {
addUserModal.userList = res.response || []
}).catch(error => {
console.error('搜索用户失败:', error)
Message.error('搜索用户失败')
}).finally(() => {
addUserModal.loading = false
})
} catch (error) {
console.error('搜索用户失败:', error)
Message.error('搜索用户失败')
addUserModal.loading = false
}
}
// 加载部门列表
const loadDepartments = async () => {
try {
await GetDepts().then((res) => {
departmentOptions.value = res.response.map(dept => ({
value: dept.dept_id,
label: dept.dept_name
}))
}).catch(error => {
console.error('获取部门数据失败:', error)
Message.error('获取部门数据失败')
})
} catch (error) {
console.error('获取部门数据失败:', error)
Message.error('获取部门数据失败')
}
}
onMounted(() => {
loadRoleList()
loadDepartments()
})
</script>
<style scoped>
.role-container {
display: flex;
min-height: calc(100vh - 150px);
/* border: 1px solid #e8eaec; */
border-radius: 4px;
overflow: auto;
gap: 16px;
}
.role-sidebar {
width: 300px;
border-right: 1px solid #e8eaec;
background-color: #fff;
overflow-y: auto;
height: 200px;
}
.role-title {
padding: 16px;
font-size: 16px;
font-weight: bold;
border-bottom: 1px solid #e8eaec;
}
.role-list {
padding: 10px 0;
}
.role-item {
display: flex;
align-items: center;
padding: 12px 16px;
cursor: pointer;
transition: background-color 0.3s;
}
.role-item:hover {
background-color: #f0f0f0;
}
.role-item.active {
background-color: #e8f7ff;
color: #2d8cf0;
}
.role-item-icon {
width: 36px;
height: 36px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-right: 12px;
color: #fff;
}
.role-admin {
background-color: #2d8cf0;
}
.role-party-office {
background-color: #19be6b;
}
.role-entrance-dept {
background-color: #ff9900;
}
.role-responsible-dept {
background-color: #ed4014;
}
.role-item-info {
flex: 1;
}
.role-name {
font-size: 14px;
margin-bottom: 4px;
}
.role-count {
font-size: 12px;
color: #808695;
}
.role-content {
display: flex;
flex-direction: column;
gap: 16px;
flex: 1;
}
.role-toolbar {
height: 100%;
display: flex;
justify-content: space-between;
/* margin-bottom: 16px; */
position: sticky;
top: 0;
background-color: #fff;
z-index: 1;
}
.search-box {
width: 280px;
}
.pagination {
/* margin-top: 16px; */
text-align: center;
position: sticky;
bottom: 0;
background-color: #fff;
z-index: 1;
}
.action-btns {
display: flex;
justify-content: center;
}
.user-avatar {
display: flex;
justify-content: center;
align-items: center;
}
.user-avatar img {
width: 100%;
height: 100%;
object-fit: cover;
}
.add-user-search {
margin-bottom: 16px;
}
.duty-dept-select {
margin-bottom: 16px;
}
</style>
\ No newline at end of file
<template>
<div class="status-monitor">
<!-- 设备状态看板 -->
<Card class="status-board">
<p slot="title">设备状态看板</p>
<div class="calendar-view">
<Calendar
v-model="currentDate"
@on-change="handleDateChange"
>
<template #month="{ date, data }">
<div>
<Badge status="success" text="打印机A: 空闲" v-if="data.day === '2025-04-15'" />
<Badge status="success" text="打印机A: 空闲" v-if="data.day === '2025-04-15'" />
</div>
</template>
</Calendar>
<div class="legend">
<Tag color="success">空闲</Tag>
<Tag color="error">占用</Tag>
<Tag color="warning">维修中</Tag>
<Tag color="default">未启用</Tag>
</div>
</div>
</Card>
</div>
</template>
<script>
export default {
name: 'StatusQuery',
data() {
return {
currentDate: new Date(),
weekDays: ['日', '一', '二', '三', '四', '五', '六'],
// 设备数据
deviceData: [
{
deviceName: '打印机A',
status: 'free',
currentUser: '-',
date: '2024-02-15'
},
{
deviceName: '复印机B',
status: 'occupied',
currentUser: '张三',
date: '2024-02-20'
},
{
deviceName: '扫描仪C',
status: 'maintenance',
currentUser: '维修部',
date: '2024-02-21'
}
],
// 维护计划配置
maintenanceColumns: [
{ title: '设备名称', key: 'deviceName' },
{ title: '维护类型', key: 'maintenanceType' },
{ title: '计划时间', key: 'plannedTime' },
{ title: '责任人', key: 'responsible' },
{ title: '状态', key: 'status' },
{ title: '操作', slot: 'action' }
],
maintenanceData: [
{
deviceName: '打印机A',
maintenanceType: '校准',
plannedTime: '2024-07-01',
responsible: '李四',
status: '待处理'
}
]
}
},
computed: {
currentMonthText() {
return `${this.currentDate.getFullYear()}年${this.currentDate.getMonth() + 1}月`
},
calendarDays() {
const year = this.currentDate.getFullYear()
const month = this.currentDate.getMonth()
const firstDay = new Date(year, month, 1)
const lastDay = new Date(year, month + 1, 0)
const days = []
// 填充上个月的日期
const firstDayWeekday = firstDay.getDay()
for(let i = firstDayWeekday - 1; i >= 0; i--) {
const date = new Date(year, month, -i)
days.push({
date: date.toISOString().split('T')[0],
dayNumber: date.getDate(),
isCurrentMonth: false,
isToday: this.isToday(date)
})
}
// 当前月的日期
for(let i = 1; i <= lastDay.getDate(); i++) {
const date = new Date(year, month, i)
days.push({
date: date.toISOString().split('T')[0],
dayNumber: i,
isCurrentMonth: true,
isToday: this.isToday(date)
})
}
// 填充下个月的日期
const remainingDays = 42 - days.length
for(let i = 1; i <= remainingDays; i++) {
const date = new Date(year, month + 1, i)
days.push({
date: date.toISOString().split('T')[0],
dayNumber: i,
isCurrentMonth: false,
isToday: this.isToday(date)
})
}
return days
}
},
methods: {
prevMonth() {
this.currentDate = new Date(this.currentDate.getFullYear(), this.currentDate.getMonth() - 1)
},
nextMonth() {
this.currentDate = new Date(this.currentDate.getFullYear(), this.currentDate.getMonth() + 1)
},
isToday(date) {
const today = new Date()
return date.getDate() === today.getDate() &&
date.getMonth() === today.getMonth() &&
date.getFullYear() === today.getFullYear()
},
getDayDevices(date) {
return this.deviceData.filter(device => device.date === date)
},
getStatusColor(status) {
const colorMap = {
free: 'success',
occupied: 'error',
maintenance: 'warning'
}
return colorMap[status]
},
getStatusText(status) {
const textMap = {
free: '空闲',
occupied: '占用',
maintenance: '维修中'
}
return textMap[status]
},
handleMaintenance(row) {
this.$Modal.confirm({
title: '维护处理',
content: `确认处理 ${row.deviceName} 的维护计划吗?`,
onOk: () => {
this.$Message.success('处理成功')
}
})
}
}
}
</script>
<style lang="less" scoped>
.status-monitor {
.status-board, .maintenance-plan {
margin-bottom: 20px;
}
.calendar-view {
.calendar-header {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
.current-month {
margin: 0 20px;
font-size: 16px;
font-weight: bold;
}
}
.calendar-grid {
border: 1px solid #eee;
.calendar-weekdays {
display: grid;
grid-template-columns: repeat(7, 1fr);
background: #f8f8f8;
.weekday {
padding: 10px;
text-align: center;
font-weight: bold;
}
}
.calendar-days {
display: grid;
grid-template-columns: repeat(7, 1fr);
.day {
min-height: 100px;
padding: 5px;
border: 1px solid #eee;
&.other-month {
background: #fafafa;
color: #999;
}
&.today {
background: #f0f9ff;
}
.day-number {
font-size: 14px;
margin-bottom: 5px;
}
.day-content {
.device-item {
margin-bottom: 3px;
}
}
}
}
}
.legend {
display: flex;
gap: 10px;
margin-top: 10px;
justify-content: center;
}
}
}
</style>
Markdown 格式
0% or
您添加了 0 人 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册 或