项目列表

This commit is contained in:
Leo_Ding 2025-06-23 10:37:35 +08:00
parent 7321cd2e17
commit cfc751a3ec
13 changed files with 392 additions and 683 deletions

View File

@ -12,7 +12,7 @@ VITE_ROUTER_BASE=/
VITE_ROUTER_HISTORY=hash VITE_ROUTER_HISTORY=hash
# api # api
VITE_API_BASIC=/ VITE_API_BASIC=http://10.10.1.6:8070
VITE_API_HTTP=/api/v1/ VITE_API_HTTP=/api/v1/
# storage # storage
VITE_STORAGE_NAMESPACE = gin-admin_local_ VITE_STORAGE_NAMESPACE = gin-admin_local_

View File

@ -11,7 +11,7 @@ VITE_PERMISSION=true
VITE_ROUTER_HISTORY=hash VITE_ROUTER_HISTORY=hash
# api # api
VITE_API_BASIC=/ VITE_API_BASIC=http://10.10.1.6:8070
VITE_API_HTTP=/api/v1/ VITE_API_HTTP=/api/v1/
# storage # storage

14
src/apis/modules/area.js Normal file
View File

@ -0,0 +1,14 @@
/**
* 区域模块接口
*/
import request from '@/utils/request'
// 获取项目列表
export const getProjectList = (params) => request.basic.get('/api/v1/companies', params)
// 获取role条数据
export const getRole = (id) => request.basic.get(`/api/v1/roles/${id}`)
// 添加条目
export const createProject = (params) => request.basic.post('/api/v1/companies', params)
// 更新role
export const updateRole = (id, params) => request.basic.put(`/api/v1/roles/${id}`, params)
// 删除role
export const delRole = (id) => request.basic.delete(`/api/v1/roles/${id}`)

View File

@ -5,3 +5,5 @@ export const getRegion = (params) => request.basic.get('/region', params)
// 获取 验证码ID // 获取 验证码ID
export const getCaptcha = (params) => request.basic.get('/api/v1/captcha/id', params) export const getCaptcha = (params) => request.basic.get('/api/v1/captcha/id', params)
//上传图片
export const uploadImg=(params)=>request.basic.post('/api/v1/upload',params,{Headers:{'Content-Type': 'multipart/form-data'}})

View File

@ -0,0 +1,168 @@
<template>
<div class="clearfix">
<a-upload list-type="picture-card" :multiple="multiple" v-model:file-list="fileList" @preview="handlePreview"
@change="handleChange" :customRequest="handleCustomRequest" :beforeUpload="beforeUpload">
<div v-if="fileList.length < fileNumber">
<plus-outlined />
<div class="ant-upload-text">上传</div>
</div>
</a-upload>
<a-modal :open="previewVisible" :footer="null" @cancel="handleCancel">
<img alt="example" style="width: 100%" :src="previewImage" />
</a-modal>
</div>
</template>
<script setup>
import { ref, watch,onMounted } from 'vue';
import { PlusOutlined } from '@ant-design/icons-vue';
import { UploadOutlined } from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';
import { config } from '@/config'
import apis from '@/apis'
const previewVisible = ref(false)
const previewImage = ref('')
const props = defineProps({
modelValue: { type: Array, default: () => [] },
headers: { type: Object, default: () => ({}) },
multiple: { type: Boolean, default: false },
maxSize: { type: Number, default: 10 }, // MB
acceptTypes: { type: String, default: '*' },
listType: { type: String, default: 'text' },
disabled: { type: Boolean, default: false },
uploadText: { type: String },
fileNumber: { type: Number, default: 6 }
});
const emit = defineEmits(['update:modelValue', 'uploadSuccess', 'uploadError']);
const uploadUrl = config('http.apiBasic') + '/api/v1/upload'
const fileList = ref([]);
//
onMounted(() => {
fileList.value = props.modelValue.map(url => ({
uid: `preview-${Date.now()}-${Math.random()}`,
name: url.substring(url.lastIndexOf('/') + 1),
status: 'done',
url: url
}));
});
//
const beforeUpload = (file) => {
const isValidType = props.acceptTypes === '*' ||
props.acceptTypes.split(',').some(type => file.name.endsWith(type.replace('*', '')));
const isValidSize = file.size / 1024 / 1024 < props.maxSize;
if (!isValidType) {
message.error(`仅支持 ${props.acceptTypes} 格式文件`);
return false;
}
if (!isValidSize) {
message.error(`文件大小不能超过 ${props.maxSize}MB`);
return false;
}
return true;
};
const handleCancel = () => {
previewVisible.value = false;
};
const getBase64 = (file) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
});
}
const handlePreview = async (file) => {
if (!file.url && !file.preview) {
file.preview = await getBase64(file.originFileObj)
}
previewImage.value = file.url || file.preview;
previewVisible.value = true;
};
// handleChange
const handleChange = ({ file, fileList: updatedList }) => {
//
if (file.status === 'done') {
const response = file.response;
if (response && response.url) {
// URL
const targetFile = updatedList.find(f => f.uid === file.uid);
if (targetFile) {
targetFile.url = response.url;
message.success(`${file.name} 上传成功`);
}
//
const urls = updatedList
.filter(item => item.status === 'done')
.map(item => item.url);
emit('update:modelValue', urls);
}
} else if (file.status === 'error') {
message.error(`${file.name} 上传失败`);
}
};
//
const handleCustomRequest = async (options) => {
const { file, onProgress, onSuccess, onError } = options;
try {
const formData = new FormData();
formData.append('file', file);
const { data } = await apis.common.uploadImg(formData);
const fullUrl = config('http.apiBasic') + data;
//
onSuccess({
uid: file.uid,
name: file.name,
status: 'done',
url: fullUrl,
response: { url: fullUrl } // responseURL
}, file);
//
emit('uploadSuccess', { file, url: fullUrl });
} catch (err) {
onError(err);
message.error('上传失败');
emit('uploadError', err);
}
};
// v-model
watch(() => props.modelValue, (newVal) => {
//
const doneFiles = fileList.value.filter(f => f.status === 'done');
const doneUrls = doneFiles.map(f => f.url);
//
if (JSON.stringify(newVal) !== JSON.stringify(doneUrls)) {
fileList.value = [
...newVal.map(url => ({
uid: `preview-${Date.now()}-${Math.random()}`,
name: url.substring(url.lastIndexOf('/') + 1),
status: 'done',
url: url
})),
...fileList.value.filter(f => f.status !== 'done')
];
}
}, { deep: true });
</script>
<style>
/* you can make up upload button and sample style by using stylesheets */
.ant-upload-select-picture-card i {
font-size: 32px;
color: #999;
}
.ant-upload-select-picture-card .ant-upload-text {
margin-top: 8px;
color: #666;
}
</style>

View File

@ -1,26 +1,14 @@
<template> <template>
<div <div ref="uploadImageRef" class="x-upload x-upload-image" :class="{
ref="uploadImageRef" 'x-upload--round': round,
class="x-upload x-upload-image" 'x-upload--disabled': disabled,
:class="{ }">
'x-upload--round': round, <a-upload v-if="showUploadBtn" :show-upload-list="false" :multiple="multiple" :before-upload="onBeforeUpload"
'x-upload--disabled': disabled, :custom-request="({ file }) => customRequest(file)" :accept="accept" :disabled="disabled">
}">
<a-upload
v-if="showUploadBtn"
:show-upload-list="false"
:multiple="multiple"
:before-upload="onBeforeUpload"
:custom-request="({ file }) => customRequest(file)"
:accept="accept"
:disabled="disabled">
<slot> <slot>
<div <div class="x-upload-btn" :class="{
class="x-upload-btn" 'x-upload-btn--hover': !disabled,
:class="{ }" :style="{
'x-upload-btn--hover': !disabled,
}"
:style="{
width: `${width}px`, width: `${width}px`,
height: `${height}px`, height: `${height}px`,
}"> }">
@ -29,9 +17,7 @@
<plus-outlined></plus-outlined> <plus-outlined></plus-outlined>
</slot> </slot>
</div> </div>
<div <div v-if="text" class="x-upload-btn__txt">
v-if="text"
class="x-upload-btn__txt">
<slot name="text"> <slot name="text">
{{ text }} {{ text }}
</slot> </slot>
@ -39,32 +25,20 @@
</div> </div>
</slot> </slot>
</a-upload> </a-upload>
<div <div v-for="(item, index) in fileList" class="x-upload-item j-upload-item" :key="item.key" :class="{
v-for="(item, index) in fileList" 'x-upload-item--error': STATUS_ENUM.is('error', item.status),
class="x-upload-item j-upload-item" }" :style="{
:key="item.key"
:class="{
'x-upload-item--error': STATUS_ENUM.is('error', item.status),
}"
:style="{
width: `${width}px`, width: `${width}px`,
height: `${height}px`, height: `${height}px`,
}"> }">
<img <img :src="item.src" alt="" />
:src="item.src"
alt="" />
<template v-if="['error', 'done'].includes(STATUS_ENUM.getKey(item.status))"> <template v-if="['error', 'done'].includes(STATUS_ENUM.getKey(item.status))">
<div class="x-upload-actions"> <div class="x-upload-actions">
<div <div v-if="STATUS_ENUM.is('done', item.status)" class="x-upload-action"
v-if="STATUS_ENUM.is('done', item.status)"
class="x-upload-action"
@click="handlePreview(item, index)"> @click="handlePreview(item, index)">
<eye-outlined /> <eye-outlined />
</div> </div>
<div <div v-if="!disabled" class="x-upload-action" @click="handleRemove(index)">
v-if="!disabled"
class="x-upload-action"
@click="handleRemove(index)">
<delete-outlined /> <delete-outlined />
</div> </div>
</div> </div>
@ -73,16 +47,11 @@
<div class="x-upload-status"> <div class="x-upload-status">
<template v-if="STATUS_ENUM.is('uploading', item.status)"> <template v-if="STATUS_ENUM.is('uploading', item.status)">
<div>{{ item.percent }}%</div> <div>{{ item.percent }}%</div>
<a-progress <a-progress :show-info="false" :stroke-width="4" :percent="item.percent" />
:show-info="false"
:stroke-width="4"
:percent="item.percent" />
</template> </template>
<template v-if="STATUS_ENUM.is('wait', item.status)"> <template v-if="STATUS_ENUM.is('wait', item.status)">
<div>{{ STATUS_ENUM.getDesc(item.status) }}</div> <div>{{ STATUS_ENUM.getDesc(item.status) }}</div>
<span <span class="x-upload-action" @click="handleCancel(item)">
class="x-upload-action"
@click="handleCancel(item)">
取消上传 取消上传
</span> </span>
</template> </template>
@ -92,11 +61,7 @@
</div> </div>
<!--裁剪--> <!--裁剪-->
<cropper-dialog <cropper-dialog v-if="cropper && !multiple" ref="cropperDialogRef" :aspect-ratio="aspectRatio" :quality="quality"
v-if="cropper && !multiple"
ref="cropperDialogRef"
:aspect-ratio="aspectRatio"
:quality="quality"
@ok="(file) => customRequest(file)" /> @ok="(file) => customRequest(file)" />
</template> </template>
@ -434,6 +399,7 @@ function trigger() {
// //
&--round { &--round {
.x-upload-btn, .x-upload-btn,
.x-upload-item { .x-upload-item {
border-radius: 10em; border-radius: 10em;

View File

@ -4,3 +4,4 @@ export { default as useMenu } from './useMenu'
export { default as useModal } from './useModal' export { default as useModal } from './useModal'
export { default as useMultiTab } from './useMultiTab' export { default as useMultiTab } from './useMultiTab'
export { default as usePagination } from './usePagination' export { default as usePagination } from './usePagination'
export { default as useSpining } from './useSpining'

19
src/hooks/useSpining.js Normal file
View File

@ -0,0 +1,19 @@
import { ref } from 'vue'
export default () => {
const spining = ref(false) // 直接使用基本类型ref
const showSpining = () => {
spining.value = true
}
const hideSpining = () => {
spining.value = false
}
return {
spining, // 直接暴露ref
showSpining,
hideSpining
}
}

View File

@ -1,169 +0,0 @@
<template>
<a-card
:body-style="{ height: 'calc(100% - 56px - 47px)', padding: 0 }"
:style="{
position: 'sticky',
top: appStore.mainOffsetTop,
height: appStore.mainHeight,
}">
<template #title>
<a-input-search placeholder="搜索部门"></a-input-search>
</template>
<x-scrollbar class="pa-8-2">
<a-spin :spinning="loading">
<a-tree
block-node
:selected-keys="selectedKeys"
:tree-data="listData"
:field-names="{ key: 'id', children: 'children' }"
@select="onSelect">
<template #title="{ title }">
<span class="ant-tree-title__name">{{ title }}</span>
<span class="ant-tree-title__actions">
<a-dropdown
:trigger="['click']"
@click.stop>
<x-action-button>
<more-outlined></more-outlined>
</x-action-button>
<template #overlay>
<a-menu>
<a-menu-item @click="$refs.editDepartmentDialogRef.handleEdit()">
添加子部门
</a-menu-item>
<a-menu-item @click="$refs.editDepartmentDialogRef.handleEdit()">
编辑
</a-menu-item>
<a-menu-item @click="handleDelete">删除</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</span>
</template>
</a-tree>
<empty
v-if="!listData.length"
:image="Empty.PRESENTED_IMAGE_SIMPLE"></empty>
</a-spin>
</x-scrollbar>
<template #actions>
<span @click="$refs.editDepartmentDialogRef.handleCreate()">
<plus-outlined></plus-outlined>
新建部门
</span>
</template>
</a-card>
<edit-department-dialog
ref="editDepartmentDialogRef"
@ok="onOk"></edit-department-dialog>
</template>
<script setup>
import { useAppStore } from '@/store'
import { ref, watch } from 'vue'
import { usePagination } from '@/hooks'
import apis from '@/apis'
import { Empty, Modal, message } from 'ant-design-vue'
import { config } from '@/config'
import { head, get, find } from 'lodash-es'
import { MoreOutlined, PlusOutlined } from '@ant-design/icons-vue'
import EditDepartmentDialog from './EditDepartmentDialog.vue'
const props = defineProps({
value: {
type: String,
default: '',
},
})
const emit = defineEmits(['change', 'update:value'])
const appStore = useAppStore()
const { listData, loading, showLoading, hideLoading } = usePagination()
const editDepartmentDialogRef = ref()
const selectedKeys = ref([props.value])
watch(
() => props.value,
(val) => {
if (val === selectedKeys.value?.[0]) return
selectedKeys.value = [val]
}
)
getList()
/**
* 获取列表
* @returns {Promise<void>}
*/
async function getList() {
try {
showLoading()
const { code, data } = await apis.common.getPageList().catch(() => {
throw new Error()
})
hideLoading()
if (config('http.code.success') === code) {
const { records } = data
listData.value = records
if (listData.value.length) {
selectedKeys.value = [get(head(listData.value), 'id')]
trigger()
}
}
} catch (error) {
hideLoading()
}
}
/**
* 删除
*/
function handleDelete({ id }) {
Modal.confirm({
title: '删除提示',
content: '确认删除?',
okText: '确认',
onOk: () => {
return new Promise((resolve, reject) => {
;(async () => {
try {
const { code } = await apis.common.del(id).catch(() => {
throw new Error()
})
if (config('http.code.success') === code) {
resolve()
message.success('删除成功')
await getList()
}
} catch (error) {
reject()
}
})()
})
},
})
}
function onSelect(keys) {
if (!keys.length) return
selectedKeys.value = keys
trigger()
}
async function onOk() {
await getList()
}
function trigger() {
const value = head(selectedKeys.value)
const record = find(listData.value, { id: value })
emit('update:value', value)
emit('change', record)
}
</script>
<style lang="less" scoped></style>

View File

@ -1,131 +0,0 @@
<template>
<a-modal
:open="modal.open"
:title="modal.title"
:width="480"
:confirm-loading="modal.confirmLoading"
:after-close="onAfterClose"
:cancel-text="cancelText"
@ok="handleOk"
@cancel="handleCancel">
<a-form
ref="formRef"
:model="formData"
:rules="formRules"
:label-col="{ style: { width: '90px' } }">
<a-form-item
label="部门名称"
name="name">
<a-input v-model:value="formData.name"></a-input>
</a-form-item>
<a-form-item
label="上级部门"
name="parent_id">
<a-tree-select v-model:value="formData.parent_id"></a-tree-select>
</a-form-item>
<a-form-item
label="部门负责人"
name="name">
<a-input v-model:value="formData.name"></a-input>
</a-form-item>
</a-form>
</a-modal>
</template>
<script setup>
import { cloneDeep } from 'lodash-es'
import { ref } from 'vue'
import { config } from '@/config'
import apis from '@/apis'
import { useForm, useModal } from '@/hooks'
const emit = defineEmits(['ok'])
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
const { formRecord, formData, formRef, formRules, resetForm } = useForm()
const cancelText = ref('取消')
/**
* 新建
*/
function handleCreate() {
showModal({
type: 'create',
title: '新建部门',
})
}
/**
* 编辑
*/
function handleEdit(record = {}) {
showModal({
type: 'edit',
title: '编辑部门',
})
formRecord.value = record
formData.value = cloneDeep(record)
}
/**
* 确定
*/
function handleOk() {
formRef.value
.validateFields()
.then(async (values) => {
try {
showLoading()
const params = {
...values,
}
let result = null
switch (modal.value.type) {
case 'create':
result = await apis.common.create(params).catch(() => {
throw new Error()
})
break
case 'edit':
result = await apis.common.update(params).catch(() => {
throw new Error()
})
break
}
hideLoading()
if (config('http.code.success') === result?.code) {
hideModal()
emit('ok')
}
} catch (error) {
hideLoading()
}
})
.catch(() => {
hideLoading()
})
}
/**
* 取消
*/
function handleCancel() {
hideModal()
}
/**
* 关闭后
*/
function onAfterClose() {
resetForm()
cancelText.value = '取消'
hideLoading()
}
defineExpose({
handleCreate,
handleEdit,
})
</script>
<style lang="less" scoped></style>

View File

@ -1,154 +1,85 @@
<template> <template>
<a-modal <a-modal :open="modal.open" :title="modal.title" :width="640" :confirm-loading="modal.confirmLoading"
:open="modal.open" :after-close="onAfterClose" :cancel-text="cancelText" :ok-text="okText" @ok="handleOk" @cancel="handleCancel">
:title="modal.title" <a-spin :spinning="spining">
:width="640" <a-form ref="formRef" :model="formData" :rules="formRules">
:confirm-loading="modal.confirmLoading" <a-card class="mb-8-2">
:after-close="onAfterClose" <a-row :gutter="12">
:cancel-text="cancelText" <a-col :span="24">
:ok-text="okText" <a-form-item :label="'项目名称'" name="name">
@ok="handleOk" <a-input :placeholder="'请输入项目名称'" v-model:value="formData.name"></a-input>
@cancel="handleCancel"> </a-form-item>
<a-form </a-col>
ref="formRef" <a-col :span="24">
:model="formData" <a-form-item :label="'状态'" name="status">
:rules="formRules" <a-radio-group v-model:value="formData.status" :options="[
:label-col="{ style: { width: '90px' } }"> { label: '启用', value: 'enabled' },
<a-card class="mb-8-2"> { label: '停用', value: 'disabled' },
<a-row :gutter="12">
<a-col :span="12">
<a-form-item
:label="$t('pages.system.user.form.username')"
name="username">
<a-input
:placeholder="$t('pages.system.user.form.username.placeholder')"
v-model:value="formData.username"></a-input>
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item
:label="$t('pages.system.user.form.password')"
name="password">
<a-input-password
v-model:value="formData.password"
:placeholder="$t('pages.system.user.form.password.placeholder')" />
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="12">
<a-col :span="12">
<a-form-item
:label="$t('pages.system.user.form.name')"
name="name">
<a-input
:placeholder="$t('pages.system.user.form.name.placeholder')"
v-model:value="formData.name"></a-input>
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item
:label="$t('pages.system.user.form.roles')"
name="roles">
<a-select
v-model:value="formData.roles"
mode="multiple"
style="width: 100%"
:placeholder="$t('pages.system.user.form.roles.placeholder')"
:options="roles"
@change="handleChange"></a-select>
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="12">
<a-col :span="12">
<a-form-item
:label="$t('pages.system.user.form.phone')"
type="tel"
name="phone">
<a-input
:placeholder="$t('pages.system.user.form.phone.placeholder')"
type="tel"
v-model:value="formData.phone"></a-input>
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item
:label="$t('pages.system.user.form.email')"
type="email"
name="email">
<a-input
:placeholder="$t('pages.system.user.form.email.placeholder')"
type="email"
v-model:value="formData.email"></a-input>
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="12">
<a-col :span="24">
<a-form-item
:label="$t('pages.system.user.form.remark')"
name="remark">
<a-textarea
:placeholder="$t('pages.system.user.form.remark.placeholder')"
v-model:value="formData.remark"></a-textarea>
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="12">
<a-col :span="24">
<a-form-item
:label="$t('pages.system.user.form.status')"
name="status">
<a-radio-group
v-model:value="formData.status"
:options="[
{ label: $t('pages.system.user.form.status.activated'), value: 'activated' },
{ label: $t('pages.system.user.form.status.freezed'), value: 'freezed' },
]"></a-radio-group> ]"></a-radio-group>
</a-form-item> </a-form-item>
</a-col> </a-col>
</a-row> <a-col :span="24">
</a-card> <a-form-item :label="'图片'">
</a-form> <gx-upload v-model="formData.fileList" accept-types=".jpg,.png,.webp" :fileNumber="1"/>
</a-form-item>
</a-col>
</a-row>
</a-card>
</a-form>
</a-spin>
</a-modal> </a-modal>
</template> </template>
<script setup> <script setup>
import { cloneDeep } from 'lodash-es' import { cloneDeep } from 'lodash-es'
import { ref } from 'vue' import { ref, onBeforeMount } from 'vue'
import { config } from '@/config' import { config } from '@/config'
import apis from '@/apis' import apis from '@/apis'
import { useForm, useModal } from '@/hooks' import { useForm, useModal, useSpining } from '@/hooks'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import dayjs from 'dayjs'
import GxUpload from '@/components/GxUpload/index.vue'
const areaFormRef = ref()
const emit = defineEmits(['ok']) const emit = defineEmits(['ok'])
const { t } = useI18n() // t const { t } = useI18n() // t
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal() const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
const { formRecord, formData, formRef, formRules, resetForm } = useForm() const { formRecord, formData, formRef, formRules, resetForm } = useForm()
const { spining, showSpining, hideSpining } = useSpining()
const cancelText = ref(t('button.cancel')) const cancelText = ref(t('button.cancel'))
const okText = ref(t('button.confirm')) const okText = ref(t('button.confirm'))
const rolesValue = ref([]) const rolesValue = ref([])
const roles = ref([]) const roles = ref([])
const imgUrl = ref('')
const areaList = ref([])
const childOpen = ref(false)
const fileList=ref([])
const formArea = ref({ name: '', status: 'enabled' })
formRules.value = { formRules.value = {
name: { required: true, message: t('pages.system.user.form.username.placeholder') }, title: { required: true, message: '请输入项目名称' },
username: { required: true, message: t('pages.system.user.form.code.placeholder') }, status: [{ required: true, message: '请选择状态', trigger: 'change' }],
status: { required: true, message: t('pages.system.user.form.status') },
roles: [{ required: true, message: t('pages.system.user.form.roles.placeholder'), trigger: 'change' }],
} }
const areaFormRules = {
/** name: [{ required: true, message: '请输入基地名称' }],
* 请求角色 status: [{ required: true, message: '请选择状态', trigger: 'change' }],
*/ // fileList: [{ required: true, message: '', trigger: 'change' }],
getRole() }
const initData = async () => {
/** try {
* select 选择框 showSpining()
*/ const { success, data, total } = await apis.recruitment.getAreasList({ pageSize: 999, page: 1, })
const handleChange = (value) => { if (config('http.code.success') === success) {
rolesValue.value = value hideSpining()
areaList.value = data.map(item => {
if (item.status === 'enabled') {
return { code: item.id, name: item.name }
}
})
}
} catch (error) {
message.error({ content: error.message })
hideSpining()
}
} }
/** /**
@ -157,27 +88,12 @@ const handleChange = (value) => {
function handleCreate() { function handleCreate() {
showModal({ showModal({
type: 'create', type: 'create',
title: t('pages.system.user.add'), title: '新增项目',
}) })
// initData()
formData.value.status = 'enabled'
} }
async function getRole() {
const { success, data } = await apis.role.getRoleList().catch(() => {
throw new Error()
})
if (!success) {
return message.error('当前角色信息错误')
}
let roleArr = []
if (data.length) {
data.forEach((item) => {
roleArr.push({
label: item.name,
value: item.id,
})
})
}
roles.value = roleArr
}
/** /**
* 编辑 * 编辑
*/ */
@ -186,93 +102,63 @@ async function handleEdit(record = {}) {
type: 'edit', type: 'edit',
title: t('pages.system.user.edit'), title: t('pages.system.user.edit'),
}) })
const { data, success } = await apis.users.getUsers(record.id).catch() const { data, success } = await apis.recruitment.getItem(record.id).catch()
if (!success) { if (!success) {
hideModal() hideModal()
return return
} }
let roles = [] formData.value = { ...data }
if (data.roles) { imgUrl.value = config('http.apiBasic') + data.img
roles = formatArr(data.roles, 'edit')
}
data.roles = roles
formRecord.value = data
formData.value = cloneDeep(data)
} }
/** /**
* 确定 * 确定
*/ */
function handleOk() { function handleOk() {
formRef.value if(formData.value.fileList.length===0) return message.error('请上传图片')
.validateFields() formRef.value.validateFields().then(async (values) => {
.then(async (values) => { try {
try { showLoading()
showLoading() const params = {
d
const params = {
...values,
roles: formatArr(rolesValue.value),
}
let result = null
switch (modal.value.type) {
case 'create':
result = await apis.users.createUsers(params).catch(() => {
throw new Error()
})
break
case 'edit':
result = await apis.users.updateUsers(formData.value.id, params).catch(() => {
throw new Error()
})
break
}
hideLoading()
if (config('http.code.success') === result?.success) {
hideModal()
emit('ok')
}
} catch (error) {
hideLoading()
} }
}) let result = null
.catch(() => { switch (modal.value.type) {
case 'create':
result = await apis.area.createProject(params).catch((error) => {
throw new Error(error)
})
break
case 'edit':
result = await apis.recruitment.updateItem(formData.value.id, params).catch(() => {
throw new Error(error)
})
break
}
hideLoading()
if (config('http.code.success') === result?.success) {
hideModal()
emit('ok')
}
} catch (error) {
message.error({ content: error.message })
hideLoading()
}
})
.catch((e) => {
console.log(e)
hideLoading() hideLoading()
}) })
} }
/**
* 对权限组 过数据格式
*/
function formatArr(data, type = '') {
const rolesArr = []
data.forEach((item) => {
roles.value.forEach((r) => {
if (type === 'edit') {
if (item.role_id === r.value) {
rolesArr.push({
value: item.role_id,
label: r.label,
})
return
}
} else if (r.value === item) {
rolesArr.push({
role_id: item,
role_name: r.label,
})
return
}
})
})
return rolesArr
}
/** /**
* 取消 * 取消
*/ */
function handleCancel() { function handleCancel() {
imgUrl.value = ''
hideModal() hideModal()
} }

View File

@ -1,44 +1,27 @@
<template> <template>
<x-search-bar class="mb-8-2"> <x-search-bar class="mb-8-2">
<template #default="{ gutter, colSpan }"> <template #default="{ gutter, colSpan }">
<a-form <a-form :model="searchFormData" layout="inline">
:label-col="{ style: { width: '100px' } }"
:model="searchFormData"
layout="inline">
<a-row :gutter="gutter"> <a-row :gutter="gutter">
<a-col v-bind="colSpan"> <a-col v-bind="colSpan">
<a-form-item <a-form-item label="岗位名称" name="title">
:label="$t('pages.system.role.form.name')" <a-input placeholder="请输入岗位名称" v-model:value="searchFormData.title"></a-input>
name="name">
<a-input
:placeholder="$t('pages.system.role.form.code.placeholder')"
v-model:value="searchFormData.name"></a-input>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col v-bind="colSpan"> <a-col v-bind="colSpan">
<a-form-item name="code"> <a-form-item label="状态" name="status">
<template #label> <a-select v-model:value="searchFormData.status" allowClear>
{{ $t('pages.system.role.form.code') }} <a-select-option value="">全部</a-select-option>
<a-tooltip :title="$t('pages.system.role.form.code')"> <a-select-option value="enabled">启用</a-select-option>
<question-circle-outlined class="ml-4-1 color-placeholder" /> <a-select-option value="disabled">停用</a-select-option>
</a-tooltip> </a-select>
</template>
<a-input
:placeholder="$t('pages.system.role.form.code.placeholder')"
v-model:value="searchFormData.code"></a-input>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col class="align-right" v-bind="colSpan">
<a-col
class="align-right"
v-bind="colSpan">
<a-space> <a-space>
<a-button @click="handleResetSearch">{{ $t('button.reset') }}</a-button> <a-button @click="handleResetSearch">{{ $t('button.reset') }}</a-button>
<a-button <a-button ghost type="primary" @click="handleSearch">
ghost
type="primary"
@click="handleSearch">
{{ $t('button.search') }} {{ $t('button.search') }}
</a-button> </a-button>
</a-space> </a-space>
@ -47,62 +30,45 @@
</a-form> </a-form>
</template> </template>
</x-search-bar> </x-search-bar>
<a-row <a-row :gutter="8" :wrap="false">
:gutter="8"
:wrap="false">
<a-col flex="auto"> <a-col flex="auto">
<a-card type="flex"> <a-card type="flex">
<x-action-bar class="mb-8-2"> <x-action-bar class="mb-8-2">
<a-button <a-button type="primary" @click="$refs.editDialogRef.handleCreate()">
v-action="'add'"
type="primary"
@click="$refs.editDialogRef.handleCreate()">
<template #icon> <template #icon>
<plus-outlined></plus-outlined> <plus-outlined></plus-outlined>
</template> </template>
{{ $t('pages.system.role.add') }} 新增项目
</a-button> </a-button>
</x-action-bar> </x-action-bar>
<a-table <a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading"
:columns="columns" :pagination="paginationState" :scroll="{ x: 1000 }" @change="onTableChange">
:data-source="listData"
:loading="loading"
:pagination="paginationState"
:scroll="{ x: 1000 }"
@change="onTableChange">
<template #bodyCell="{ column, record }"> <template #bodyCell="{ column, record }">
<template v-if="'statusType' === column.key">
<!--状态--> <template v-if="column.dataIndex === 'introduce'">
<a-tag <a-tooltip :title="record.introduce">
v-if="statusTypeEnum.is('enabled', record.status)" <div class="text-ellipsis">{{ record.introduce }}</div>
color="processing"> </a-tooltip>
{{ statusTypeEnum.getDesc(record.status) }}
</a-tag>
<!--状态-->
<a-tag
v-if="statusTypeEnum.is('disabled', record.status)"
color="processing">
{{ statusTypeEnum.getDesc(record.status) }}
</a-tag>
</template> </template>
<template v-if="column.dataIndex === 'duty'">
<template v-if="'createAt' === column.key"> <a-tooltip :title="record.duty">
{{ formatUtcDateTime(record.created_at) }} <div class="text-ellipsis">{{ record.duty }}</div>
</a-tooltip>
</template>
<template v-if="'status' === column.dataIndex">
<a-tag v-if="record.status === 'enabled'" :color="'green'">启用</a-tag>
<a-tag v-if="record.status === 'disabled'" :color="'red'">停用</a-tag>
</template> </template>
<template v-if="'action' === column.key"> <template v-if="'action' === column.key">
<x-action-button @click="$refs.editDialogRef.handleEdit(record)"> <x-action-button @click="$refs.editDialogRef.handleEdit(record)">
<a-tooltip> <a-tooltip>
<template #title> {{ $t('pages.system.role.edit') }}</template> <template #title> {{ $t('pages.system.user.edit') }}</template>
<edit-outlined /> <edit-outlined /> </a-tooltip></x-action-button>
</a-tooltip> <x-action-button @click="handleDelete(record)">
</x-action-button>
<x-action-button @click="handleRemove(record)">
<a-tooltip> <a-tooltip>
<template #title> {{ $t('pages.system.delete') }}</template> <template #title>{{ $t('pages.system.delete') }}</template>
<delete-outlined style="color: #ff4d4f" /> <delete-outlined style="color: #ff4d4f" /> </a-tooltip></x-action-button>
</a-tooltip>
</x-action-button>
</template> </template>
</template> </template>
</a-table> </a-table>
@ -110,9 +76,7 @@
</a-col> </a-col>
</a-row> </a-row>
<edit-dialog <edit-dialog ref="editDialogRef" @ok="onOk"></edit-dialog>
ref="editDialogRef"
@ok="onOk"></edit-dialog>
</template> </template>
<script setup> <script setup>
@ -121,32 +85,28 @@ import { ref } from 'vue'
import apis from '@/apis' import apis from '@/apis'
import { formatUtcDateTime } from '@/utils/util' import { formatUtcDateTime } from '@/utils/util'
import { config } from '@/config' import { config } from '@/config'
import { statusTypeEnum } from '@/enums/system' import { statusUserTypeEnum } from '@/enums/system'
import { usePagination, useForm } from '@/hooks' import { usePagination } from '@/hooks'
import EditDialog from './components/EditDialog.vue' import EditDialog from './components/EditDialog.vue'
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue' import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
defineOptions({ defineOptions({
name: 'systemRole', name: 'homeBanner',
}) })
const { t } = useI18n() // t const { t } = useI18n() // t
const columns = [ const columns = [
{ title: t('pages.system.role.form.code'), dataIndex: 'code', width: 240 }, { title: '图片', dataIndex: 'img', width: 120, },
{ title: t('pages.system.role.form.name'), dataIndex: 'name' }, { title: '项目名称', dataIndex: 'name', key: 'title', width: 150 },
{ title: t('pages.system.role.form.status'), dataIndex: 'status', key: 'statusType', width: 80 }, { title: '状态', dataIndex: 'status', key: 'introduce',width:100},
{ title: t('pages.system.role.form.sequence'), dataIndex: 'sequence', width: 100 }, { title: t('button.action'), key: 'action', fixed: 'right', width: 100, align: 'center' },
{ title: t('pages.system.role.form.created_at'), key: 'createAt', fixed: 'right', width: 120 },
{ title: t('button.action'), key: 'action', fixed: 'right', width: 120 },
] ]
const { listData, loading, showLoading, hideLoading, paginationState, searchFormData, resetPagination } = const { listData, loading, showLoading, hideLoading, paginationState, resetPagination, searchFormData } =
usePagination() usePagination()
const { resetForm } = useForm()
const editDialogRef = ref() const editDialogRef = ref()
getPageList() getPageList()
/** /**
* 获取用户列表 * 获取用户列表
* @returns {Promise<void>} * @returns {Promise<void>}
@ -155,8 +115,8 @@ async function getPageList() {
try { try {
showLoading() showLoading()
const { pageSize, current } = paginationState const { pageSize, current } = paginationState
const { success, data, total } = await apis.role const { success, data, total } = await apis.area
.getRoleList({ .getProjectList({
pageSize, pageSize,
page: current, page: current,
...searchFormData.value, ...searchFormData.value,
@ -175,18 +135,18 @@ async function getPageList() {
} }
/** /**
* *
*/ */
function handleRemove({ id }) { function handleDelete({ id }) {
Modal.confirm({ Modal.confirm({
title: t('pages.system.role.delTip'), title: t('pages.system.user.delTip'),
content: t('button.confirm'), content: t('button.confirm'),
okText: t('button.confirm'), okText: t('button.confirm'),
onOk: () => { onOk: () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
;(async () => { ; (async () => {
try { try {
const { success } = await apis.role.delRole(id).catch(() => { const { success } = await apis.recruitment.delItem(id).catch(() => {
throw new Error() throw new Error()
}) })
if (config('http.code.success') === success) { if (config('http.code.success') === success) {
@ -212,6 +172,13 @@ function onTableChange({ current, pageSize }) {
getPageList() getPageList()
} }
/**
* 搜索
*/
function handleSearch() {
resetPagination()
getPageList()
}
/** /**
* 重置 * 重置
*/ */
@ -220,20 +187,11 @@ function handleResetSearch() {
resetPagination() resetPagination()
getPageList() getPageList()
} }
/**
* 搜索
*/
function handleSearch() {
resetForm()
resetPagination()
getPageList()
}
/** /**
* 编辑完成 * 编辑完成
*/ */
async function onOk() { async function onOk() {
message.success(t('component.message.success.delete'))
await getPageList() await getPageList()
} }
</script> </script>

View File

@ -215,10 +215,10 @@
resolved "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.8.1.tgz" resolved "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.8.1.tgz"
integrity sha512-KOEGMu6dmJZtpadb476IsZBclKvILjopjUii3V+7MnXIQCYh8W3NgNcgwo21n9LXZX6EDIKvqfjYxXebDwxKmQ== integrity sha512-KOEGMu6dmJZtpadb476IsZBclKvILjopjUii3V+7MnXIQCYh8W3NgNcgwo21n9LXZX6EDIKvqfjYxXebDwxKmQ==
"@esbuild/darwin-arm64@0.18.20": "@esbuild/win32-x64@0.18.20":
version "0.18.20" version "0.18.20"
resolved "https://registry.npmmirror.com/@esbuild/darwin-arm64/-/darwin-arm64-0.18.20.tgz" resolved "https://registry.npmmirror.com/@esbuild/win32-x64/-/win32-x64-0.18.20.tgz"
integrity sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA== integrity sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==
"@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": "@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0":
version "4.4.0" version "4.4.0"
@ -1323,11 +1323,6 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==
fsevents@~2.3.2:
version "2.3.2"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
get-caller-file@^2.0.1, get-caller-file@^2.0.5: get-caller-file@^2.0.1, get-caller-file@^2.0.5:
version "2.0.5" version "2.0.5"
resolved "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz" resolved "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz"