Initial commit

This commit is contained in:
南宁网宿科技
2023-06-03 23:57:39 +08:00
commit 13bed2bafb
1017 changed files with 175796 additions and 0 deletions
@@ -0,0 +1,223 @@
<!-- 搜索表单 -->
<template>
<a-space :size="10" style="flex-wrap: wrap">
<a-button type="primary" class="ele-btn-icon" @click="add">
<template #icon>
<PlusOutlined />
</template>
<span>添加仓库</span>
</a-button>
<a-upload
:before-upload="importBatch"
:show-upload-list="false"
accept=".xls,.xlsx"
>
<a-button class="ele-btn-icon"> <DownloadOutlined />批量导入 </a-button>
</a-upload>
<a-button class="ele-btn-icon">
<span>下载仓库模板</span>
</a-button>
<a-upload
:before-upload="importBatch"
:show-upload-list="false"
accept=".xls,.xlsx"
>
<a-button class="ele-btn-icon"> <UploadOutlined />导出 </a-button>
</a-upload>
<a-button
danger
type="primary"
class="ele-btn-icon"
v-if="selection.length > 0"
@click="removeBatch"
>
<template #icon>
<DeleteOutlined />
</template>
<span>批量删除</span>
</a-button>
<!-- <a-button @click="batchMove" v-if="selection.length > 0">-->
<!-- <template #icon>-->
<!-- <UserSwitchOutlined />-->
<!-- </template>-->
<!-- 批量转移-->
<!-- </a-button>-->
<a-input-search
allow-clear
placeholder="请输入关键词"
v-model:value="searchText"
@pressEnter="search"
@search="search"
/>
</a-space>
</template>
<script lang="ts" setup>
import {
PlusOutlined,
DeleteOutlined,
UploadOutlined,
DownloadOutlined
} from '@ant-design/icons-vue';
import useSearch from '@/utils/use-search';
import type { CustomerParam } from '@/api/oa/customer/model';
import { ref, watch } from 'vue';
import { utils, read } from 'xlsx';
// import { assignObject } from 'ele-admin-pro';
import { message } from 'ant-design-vue/es';
const props = withDefaults(
defineProps<{
// 选中的角色
selection?: [];
}>(),
{}
);
const emit = defineEmits<{
(e: 'search', where?: CustomerParam): void;
(e: 'add'): void;
(e: 'remove'): void;
(e: 'batchMove'): void;
}>();
// 表单数据
const { where } = useSearch<CustomerParam>({
customerName: '',
customerCode: '',
nickname: '',
keywords: '',
userId: undefined
});
// 下来选项
// 搜索内容
const searchText = ref('');
/* 搜索 */
const search = () => {
where.keywords = searchText.value;
emit('search', where);
};
// 新增
const add = () => {
emit('add');
};
// 导入数据的列
const importTitle = ref<string[]>(['A', 'B', 'C', 'D', 'E', 'F', 'G']);
// 导入的数据
const importData = ref<Record<string, any>[]>([]);
// 导入数据二维数组形式
const importDataAoa = ref<(string | number)[][]>([]);
/* 导入本地 excel 文件 */
const importBatch = (file: File) => {
if (
![
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
].includes(file.type)
) {
message.error('只能选择 excel 文件');
return false;
}
if (file.size / 1024 / 1024 > 20) {
message.error('大小不能超过 20MB');
return false;
}
const reader = new FileReader();
reader.onload = (e) => {
const data = new Uint8Array(e.target?.result as any);
const workbook = read(data, { type: 'array' });
const sheetNames = workbook.SheetNames;
const worksheet = workbook.Sheets[sheetNames[0]];
// 解析成二维数组
const aoa = utils.sheet_to_json<string[]>(worksheet, { header: 1 });
// 生成表格需要的数据
let list: Record<string, any>[] = [];
let maxCols = 0;
let title: string[] = [];
aoa.forEach((d) => {
if (d.length > maxCols) {
maxCols = d.length;
}
const row = {};
for (let i = 0; i < d.length; i++) {
const key = getCharByIndex(i);
row[key] = d[i];
row['__colspan__' + key] = 1;
row['__rowspan__' + key] = 1;
}
list.push(row);
});
for (let i = 0; i < maxCols; i++) {
title.push(getCharByIndex(i));
}
importTitle.value = title;
importData.value = list;
importDataAoa.value = aoa;
};
console.log(importData.value);
console.log(importDataAoa.value);
reader.readAsArrayBuffer(file);
return false;
};
/* 生成Excel列字母序号 */
const getCharByIndex = (index: number) => {
const chars = [
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z'
];
if (index < chars.length) {
return chars[index];
}
const n = parseInt(String(index / chars.length));
const m = index % chars.length;
return chars[n] + chars[m];
};
// 转移
// const batchMove = () => {
// emit('batchMove');
// };
// 批量删除
const removeBatch = () => {
emit('remove');
};
const onClear = () => {
where.userId = undefined;
search();
};
watch(
() => props.selection,
() => {}
);
</script>
@@ -0,0 +1,330 @@
<!-- 用户编辑弹窗 -->
<template>
<ele-modal
:width="750"
:visible="visible"
:confirm-loading="loading"
:maskClosable="false"
:maxable="maxable"
:title="isUpdate ? '编辑仓库' : '添加仓库'"
:body-style="{ paddingBottom: '8px' }"
@update:visible="updateVisible"
@ok="save"
>
<a-form
:label-col="{ md: { span: 6 }, sm: { span: 20 }, xs: { span: 24 } }"
:wrapper-col="{ md: { span: 24 }, sm: { span: 20 }, xs: { span: 24 } }"
>
<a-row :gutter="16">
<a-col :md="12" :sm="24" :xs="24">
<a-form-item label="仓库名称" name="warehouseName">
<a-input
allow-clear
:maxlength="30"
placeholder="请输入仓库名称"
v-model:value="form.warehouseName"
/>
</a-form-item>
<a-form-item label="负责人" name="warehouseKeeper">
<a-input
allow-clear
:maxlength="30"
placeholder="请输入负责人"
v-model:value="form.warehouseKeeper"
/>
</a-form-item>
<a-form-item label="负责人电话" name="warehousePhone">
<a-input
allow-clear
:maxlength="30"
placeholder="请输入负责人联系电话"
v-model:value="form.warehousePhone"
/>
</a-form-item>
<a-form-item label="排序" name="sortNumber">
<a-input
allow-clear
:maxlength="20"
placeholder="排序"
v-model:value="form.sortNumber"
/>
</a-form-item>
<a-form-item label="备注" name="comments">
<a-textarea
:rows="4"
:maxlength="200"
placeholder="请输入备注"
v-model:value="form.comments"
/>
</a-form-item>
</a-col>
<a-col :md="12" :sm="24" :xs="24">
<a-form-item label="所属区域" name="region">
<a-input-group compact>
<a-input
disabled
style="width: calc(100% - 32px)"
v-model:value="form.region"
placeholder="所属区域"
@search="onSearch"
/>
<a-tooltip title="选择位置">
<a-button @click="openMapPicker">
<template #icon><EnvironmentOutlined /></template>
</a-button>
</a-tooltip>
</a-input-group>
</a-form-item>
<a-form-item label="区域名称" name="regionName">
<a-input
allow-clear
:maxlength="30"
placeholder="请输入区域名称"
v-model:value="form.regionName"
/>
</a-form-item>
<a-form-item
label="联系地址"
name="address"
>
<a-input
allow-clear
placeholder="请填写联系地址"
v-model:value="form.address"
/>
</a-form-item>
<a-form-item label="经度" name="longitude">
<a-input
allow-clear
:maxlength="30"
disabled
placeholder="请输入经度"
v-model:value="form.longitude"
/>
</a-form-item>
<a-form-item label="纬度" name="latitude">
<a-input
allow-clear
:maxlength="30"
disabled
placeholder="请输入纬度"
v-model:value="form.latitude"
/>
</a-form-item>
</a-col>
</a-row>
<!-- 地图位置选择弹窗 -->
<ele-map-picker
:need-city="true"
:dark-mode="darkMode"
v-model:visible="showMap"
:center="[108.374959, 22.767024]"
:search-type="1"
:zoom="12"
@done="onDone"
/>
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import {ref, reactive, watch, computed} from 'vue';
import { Form, message } from 'ant-design-vue';
import { assignObject } from 'ele-admin-pro';
import { addWarehouse, updateWarehouse } from '@/api/tower/warehouse';
import type { Warehouse } from '@/api/tower/warehouse/model';
import { uploadFile } from '@/api/system/file';
import type { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
import { FILE_SERVER } from '@/config/setting';
import { useUserStore } from '@/store/modules/user';
import {
EnvironmentOutlined
} from '@ant-design/icons-vue';
import { CenterPoint } from "ele-admin-pro/es/ele-map-picker/types";
import { useThemeStore } from "@/store/modules/theme";
import { storeToRefs } from "pinia";
const userStore = useUserStore();
// 当前用户信息
const loginUser = computed(() => userStore.info ?? {});
// 是否是修改
const isUpdate = ref(false);
const useForm = Form.useForm;
const themeStore = useThemeStore();
const { darkMode } = storeToRefs(themeStore);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 修改回显的数据
data?: Warehouse | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 用户信息
const form = reactive<Warehouse>({
warehouseName: '',
warehouseKeeper: undefined,
warehousePhone: '',
regionName: '',
longitude: '',
latitude: '',
country: '',
province: '',
city: '',
region: '',
address: '',
status: 0,
userId: undefined,
comments: '',
sortNumber: 100,
warehouseId: 0,
});
// 已上传数据, 可赋初始值用于回显
const images = ref(<any>[]);
// 省市区
const city = ref<string[]>([]);
// 是否显示地图选择弹窗
const showMap = ref(false);
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
/* 打开位置选择 */
const openMapPicker = () => {
showMap.value = true;
};
// 选择地区
const onChangeRegion = (value) => {
form.province = value[0];
form.city = value[1];
form.region = value[2];
};
/* 地图选择后回调 */
const onDone = (location: CenterPoint) => {
console.log(location);
city.value = [
`${location.city?.province}`,
`${location.city?.city}`,
`${location.city?.district}`
];
form.province = `${location.city?.province}`;
form.city = `${location.city?.city}`;
form.region = `${location.city?.district}`;
form.regionName = `${location.city?.city}${location.city?.district}`;
form.address = `${location.address}`;
form.latitude = `${location.lat}`;
form.longitude = `${location.lng}`;
showMap.value = false;
};
// 表单验证规则
const rules = reactive({
warehouseName: [
{
required: true,
type: 'string',
message: '请输入仓库名称',
trigger: 'blur'
}
],
warehouseCode: [
{
required: true,
type: 'string',
message: '请输入合法的IP地址',
trigger: 'blur'
}
],
progress: [
{
required: true,
type: 'string',
message: '请选择跟进状态',
trigger: 'blur'
}
]
});
const { resetFields, validate, validateInfos } = useForm(form, rules);
/* 保存编辑 */
const save = () => {
validate()
.then(() => {
loading.value = true;
// 去除空格
form.warehouseName = form.warehouseName?.replace(/\s*/g, '');
// 判断权限
// if (loginUser.value.roles?.[0].roleCode != 'admin'){
// form.status = '1';
// }
const data = {
...form
};
// 转字符串
const saveOrUpdate = isUpdate.value ? updateWarehouse : addWarehouse;
saveOrUpdate(data)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
})
.catch(() => {});
};
// 上传文件
const onUpload = (d: ItemType) => {
uploadFile(<File>d.file)
.then((result) => {
form.warehouseAvatar = result.path;
message.success('上传成功');
})
.catch((e) => {
message.error(e.message);
});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
if (props.data) {
loading.value = false;
// 头像赋值
images.value = [];
if(props.data.warehouseAvatar){
images.value.push({ uid:1, url: FILE_SERVER + props.data.warehouseAvatar, status: '' });
}
assignObject(form, props.data);
isUpdate.value = true;
} else {
isUpdate.value = false;
}
} else {
resetFields();
}
}
);
</script>
<style lang="less"></style>
+40
View File
@@ -0,0 +1,40 @@
<template>
<div class="page">
<div class="ele-body">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<list />
</a-card>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import List from './list.vue';
// 加载状态
const loading = ref(true);
/* 查询 */
const query = () => {
loading.value = true;
};
query();
</script>
<script lang="ts">
export default {
name: 'Customer'
};
</script>
<style lang="less" scoped>
.sys-organization-list {
padding: 12px 6px;
height: calc(100vh - 242px);
border-width: 1px;
border-style: solid;
overflow: auto;
}
</style>
+256
View File
@@ -0,0 +1,256 @@
<template>
<div class="ele-body">
<!-- 表格 -->
<ele-pro-table
ref="tableRef"
row-key="warehouseId"
:columns="columns"
:datasource="datasource"
v-model:selection="selection"
tool-class="ele-toolbar-form"
:scroll="{ x: 800 }"
class="sys-org-table"
>
<template #toolbar>
<search
@search="reload"
:selection="selection"
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'warehouseName'">
<a-tooltip title="查看详情">
<a href="#" @click="openEdit(record)">{{ record.warehouseName }}</a>
</a-tooltip>
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 0" color="green">正常</a-tag>
<a-tag v-if="record.status === 1" color="red">待审核</a-tag>
<a-tag v-if="record.status === 2" color="purple">已驳回</a-tag>
</template>
<template v-if="column.key === 'region'">
<a-tooltip
:title="`${record.province} ${record.city} ${record.region}`"
>
<span>{{ `${record.city}${record.region}` }}</span>
</a-tooltip>
</template>
<template v-if="column.key === 'createTime'">
<a-tooltip :title="`${toDateString(record.createTime)}`">
{{ timeAgo(record.createTime) }}
</a-tooltip>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a-popconfirm
title="确定要删除此记录吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
<!-- 编辑弹窗 -->
<WarehouseEdit v-model:visible="showEdit" :data="current" @done="reload" />
</div>
</template>
<script lang="ts" setup>
import { computed, createVNode, ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import { toDateString } from 'ele-admin-pro';
import Search from './components/search.vue';
import WarehouseEdit from './components/warehouse-edit.vue';
import {
pageWarehouse,
removeWarehouse,
removeBatchWarehouse
} from '@/api/tower/warehouse';
import { timeAgo } from 'ele-admin-pro';
import type { Warehouse, WarehouseParam } from '@/api/tower/warehouse/model';
import { useUserStore } from '@/store/modules/user';
// 当前用户信息
const userStore = useUserStore();
const loginUser = computed(() => userStore.info ?? {});
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据
const selection = ref<Warehouse[]>([]);
// 当前编辑数据
const current = ref<Warehouse | null>(null);
// 是否显示资产详情
const showInfo = ref(false);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 是否显示批量移动弹窗
const showMove = ref(false);
// 表格数据源
const datasource: DatasourceFunction = ({
page,
limit,
where,
orders,
filters
}) => {
if (filters) {
where.status = filters.status;
}
return pageWarehouse({
...where,
...orders,
page,
limit
});
};
// 表格列配置
const columns = ref<ColumnItem[]>([
{
key: 'index',
width: 48,
align: 'center',
fixed: 'left',
hideInSetting: true,
customRender: ({ index }) => index + (tableRef.value?.tableIndex ?? 0)
},
{
title: '仓库名称',
dataIndex: 'warehouseName',
key: 'warehouseName',
ellipsis: true
},
{
title: '仓库负责人',
dataIndex: 'warehouseKeeper'
},
{
title: '负责人电话',
dataIndex: 'warehousePhone'
},
{
title: '所在区域',
dataIndex: 'region',
key: 'region'
},
{
title: '仓库地址',
dataIndex: 'address'
},
{
title: '塔吊数',
dataIndex: 'tower'
},
{
title: '升降机数',
dataIndex: 'lift'
},
{
title: '操作',
key: 'action',
width: 200,
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: WarehouseParam) => {
console.log(where);
selection.value = [];
tableRef?.value?.reload({ where: where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: Warehouse) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 删除单个 */
const remove = (row: Warehouse) => {
const hide = message.loading('请求中..', 0);
removeWarehouse(row.warehouseId)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchWarehouse(
selection.value.map((d) => {
if (loginUser.value.userId === d.userId) {
return d.warehouseId;
}
})
)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
</script>
<script lang="ts">
export default {
name: 'TowerWarehouse'
};
</script>
<style lang="less" scoped>
.sys-org-table :deep(.ant-table-body) {
overflow: auto !important;
overflow: overlay !important;
}
.sys-org-table :deep(.ant-table-pagination.ant-pagination) {
padding: 0 4px;
margin-bottom: 0;
}
</style>