feat: 设备台账
This commit is contained in:
@@ -37,13 +37,7 @@ export const appConfig = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
timeout: 60 * 1000,
|
timeout: 60 * 1000,
|
||||||
userLoginApi: () => {
|
userLoginApi: '/carbon-smart/user/login',
|
||||||
return {
|
|
||||||
code: 200,
|
|
||||||
success: true,
|
|
||||||
data: { userToken: 123123123 },
|
|
||||||
};
|
|
||||||
},
|
|
||||||
userResourceApi: () => {
|
userResourceApi: () => {
|
||||||
return { data: mockResource.menus };
|
return { data: mockResource.menus };
|
||||||
},
|
},
|
||||||
|
@@ -1,13 +1,14 @@
|
|||||||
import { dateUtil } from '/nerv-lib/util/date-util';
|
import { dateUtil } from '/nerv-lib/util/date-util';
|
||||||
import { data } from './mock.json';
|
import data from './mock.json';
|
||||||
|
|
||||||
export const tableConfig = {
|
export const tableConfig = {
|
||||||
title: '设备台账',
|
title: '设备台账',
|
||||||
api: '/carbon_emission/device/getDeviceList',
|
api: '/carbon_emission/device/getDeviceList',
|
||||||
treeConfig: {
|
treeConfig: {
|
||||||
dynamicParams: { abc: 'title', key: 'key' },
|
|
||||||
defaultExpandAll: true,
|
defaultExpandAll: true,
|
||||||
treeData: data,
|
api: () => {
|
||||||
|
return Promise.resolve(data);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
page: 0,
|
page: 0,
|
||||||
|
@@ -11,5 +11,9 @@ const proxy = {
|
|||||||
target: 'http://140.210.143.1:14492',
|
target: 'http://140.210.143.1:14492',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
|
'/carbon-smart': {
|
||||||
|
target: 'http://192.168.100.115:8224/api',
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
export default configFun({ dirname, proxy, serviceMode: 'saas', baseDir: '../' });
|
export default configFun({ dirname, proxy, serviceMode: 'saas', baseDir: '../' });
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="ns-table-container">
|
<div class="ns-table-container">
|
||||||
<div class="ns-part-tree" v-if="!isEmpty(treeConfig)">
|
<div class="ns-part-tree" v-if="!isEmpty(treeConfig)">
|
||||||
<ns-tree v-if="getTreeData.length" v-bind="getTreeBindValue" @select="treeSelect" />
|
<ns-tree-api v-bind="getTreeBindValue" @select="treeSelect" />
|
||||||
</div>
|
</div>
|
||||||
<div class="ns-part-table">
|
<div class="ns-part-table">
|
||||||
<a-spin :spinning="tableState.loading">
|
<a-spin :spinning="tableState.loading">
|
||||||
|
@@ -1,72 +1,64 @@
|
|||||||
<template>
|
<template>
|
||||||
<ns-tree v-bind="getBindValue">
|
<ns-tree v-if="treeData.length" v-bind="getBindValue">
|
||||||
<template #[item]="data" v-for="item in Object.keys($slots)" :key="item">
|
<template #[item]="data" v-for="item in Object.keys($slots)" :key="item">
|
||||||
<slot :name="item" v-bind="data || {}"></slot>
|
<slot :name="item" v-bind="data || {}"></slot>
|
||||||
</template>
|
</template>
|
||||||
</ns-tree>
|
</ns-tree>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { computed, defineComponent, ref, unref } from 'vue';
|
import { computed, ref, unref, useAttrs } from 'vue';
|
||||||
import { TreeDataItem } from 'ant-design-vue/es/tree/Tree';
|
import { TreeDataItem } from 'ant-design-vue/es/tree/Tree';
|
||||||
import { http } from '/nerv-lib/util/http';
|
import { useApi } from '/nerv-lib/use/use-api';
|
||||||
|
import { AxiosRequestConfig } from 'axios';
|
||||||
import { get } from 'lodash-es';
|
import { get } from 'lodash-es';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
export default defineComponent({
|
interface Props {
|
||||||
|
api: string | Function | object;
|
||||||
|
params?: object;
|
||||||
|
defaultParams?: object;
|
||||||
|
transform?: Function;
|
||||||
|
resultField?: string;
|
||||||
|
defaultExpandAll?: boolean;
|
||||||
|
blockNode?: boolean;
|
||||||
|
}
|
||||||
|
defineOptions({
|
||||||
name: 'NsTreeApi',
|
name: 'NsTreeApi',
|
||||||
props: {
|
|
||||||
api: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
params: {
|
|
||||||
type: Object,
|
|
||||||
},
|
|
||||||
transform: {
|
|
||||||
type: Function,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
resultField: {
|
|
||||||
type: String,
|
|
||||||
default: 'data.data',
|
|
||||||
},
|
|
||||||
defaultExpandAll: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
blockNode: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
setup(props, { attrs }) {
|
|
||||||
const treeData = ref<TreeDataItem[]>([]);
|
|
||||||
const getBindValue = computed(() => ({
|
|
||||||
...attrs,
|
|
||||||
...props,
|
|
||||||
treeData: treeData.value,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const getData = () => {
|
|
||||||
const { params, transform, resultField } = props;
|
|
||||||
treeData.value = [];
|
|
||||||
http.get(props.api, unref(params)).then((res) => {
|
|
||||||
let data = [];
|
|
||||||
if (resultField) {
|
|
||||||
data = get(res, resultField);
|
|
||||||
}
|
|
||||||
if (transform) {
|
|
||||||
treeData.value = transform(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
getData();
|
|
||||||
|
|
||||||
return {
|
|
||||||
treeData,
|
|
||||||
getBindValue,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
|
resultField: 'data',
|
||||||
|
blockNode: true,
|
||||||
|
defaultExpandAll: true,
|
||||||
|
transform: (data) => data,
|
||||||
|
});
|
||||||
|
const treeData = ref<TreeDataItem[]>([]);
|
||||||
|
const { httpRequest } = useApi();
|
||||||
|
const requestConfig: AxiosRequestConfig = { method: 'get' };
|
||||||
|
const route = useRoute();
|
||||||
|
const attrs = useAttrs();
|
||||||
|
|
||||||
|
const getBindValue = computed(() => ({
|
||||||
|
...attrs,
|
||||||
|
...props,
|
||||||
|
treeData: treeData.value,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const getData = () => {
|
||||||
|
const { api, defaultParams, transform, resultField } = props;
|
||||||
|
|
||||||
|
treeData.value = [];
|
||||||
|
if (!api) return;
|
||||||
|
httpRequest({
|
||||||
|
api,
|
||||||
|
params: { ...route.params, ...route.query, ...defaultParams },
|
||||||
|
pathParams: { ...route.params, ...route.query },
|
||||||
|
requestConfig,
|
||||||
|
}).then((res) => {
|
||||||
|
let data = [];
|
||||||
|
data = get(res, resultField);
|
||||||
|
treeData.value = transform(data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
getData();
|
||||||
</script>
|
</script>
|
||||||
<style lang="less" scoped></style>
|
<style lang="less" scoped></style>
|
||||||
|
@@ -85,7 +85,7 @@
|
|||||||
}
|
}
|
||||||
if (userName.value !== '' && password.value !== '') {
|
if (userName.value !== '' && password.value !== '') {
|
||||||
errorShow.value = false;
|
errorShow.value = false;
|
||||||
let data = JSON.stringify({ userName: userName.value, password: password.value });
|
let data = JSON.stringify({ accountNo: userName.value, password: password.value });
|
||||||
// Cookies.set('nervsid', 'mockdata');
|
// Cookies.set('nervsid', 'mockdata');
|
||||||
// router.replace({ name: 'root' });
|
// router.replace({ name: 'root' });
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@
|
|||||||
const res = await configStore.userLogin(JSON.parse(data));
|
const res = await configStore.userLogin(JSON.parse(data));
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
if (res.data?.userToken) {
|
if (res.data?.userToken) {
|
||||||
Cookies.set('nervsid', res.data?.userToken);
|
Cookies.set('token', res.data?.userToken);
|
||||||
}
|
}
|
||||||
const info = await configStore.userInfo();
|
const info = await configStore.userInfo();
|
||||||
info.success
|
info.success
|
||||||
|
Reference in New Issue
Block a user