代码生成优化

This commit is contained in:
xiangheng
2024-06-17 22:29:30 +08:00
parent a700a39992
commit 9de418ce1d
20 changed files with 1228 additions and 361 deletions

View File

@@ -0,0 +1,103 @@
import { request } from '@/utils/request'
import { clearObjEmpty } from '@/utils/utils'
import type { Pages } from '@/utils/request'
export type type_monitor_client = {
id?: number;
projectKey?: string;
clientId?: string;
userId?: string;
os?: string;
browser?: string;
city?: string;
width?: number;
height?: number;
ua?: string;
createTime?: string;
clientTime?: string;
}
// 查询
export type type_monitor_client_query = {
projectKey?: string;
clientId?: string;
userId?: string;
os?: string;
browser?: string;
city?: string;
width?: number;
height?: number;
ua?: string;
createTimeStart?: string;
createTimeEnd?: string;
clientTimeStart?: string;
clientTimeEnd?: string;
}
// 添加编辑
export type type_monitor_client_edit = {
id?: number;
clientId?: string;
userId?: string;
os?: string;
browser?: string;
city?: string;
width?: number;
height?: number;
ua?: string;
clientTime?: string;
}
// 监控-客户端信息列表
export function monitor_client_list(params?: type_monitor_client_query) {
return request<Pages<type_monitor_client>>({
url: '/monitor_client/list',
method: 'GET',
data: clearObjEmpty(params)
})
}
// 监控-客户端信息列表-所有
export function monitor_client_list_all(params?: type_monitor_client_query) {
return request<type_monitor_client[]>({
url: '/monitor_client/listAll',
method: 'GET',
data: clearObjEmpty(params)
})
}
// 监控-客户端信息详情
export function monitor_client_detail(id: number | string) {
return request<type_monitor_client>({
url: '/monitor_client/detail',
method: 'GET',
data: { id }
})
}
// 监控-客户端信息新增
export function monitor_client_add(data: type_monitor_client_edit) {
return request<null>({
url: '/monitor_client/add',
method: "POST",
data,
});
}
// 监控-客户端信息编辑
export function monitor_client_edit(data: type_monitor_client_edit) {
return request<null>({
url: '/monitor_client/edit',
method: "POST",
data,
});
}
// 监控-客户端信息删除
export function monitor_client_delete(id: number | string) {
return request<null>({
url: '/monitor_client/del',
method: "POST",
data:{
id
},
});
}

View File

@@ -0,0 +1,31 @@
<template>
<view style="flex: 1" @click="calendarsRef.open()">
<uv-input :modelValue="title" :readonly="true" placeholder="请选择时间">
</uv-input>
</view>
<uv-calendars ref="calendarsRef" :date="props.time" @confirm="Confirm" />
</template>
<script setup>
import { ref, computed } from "vue";
const emit = defineEmits(["update:time"]);
const props = defineProps({
time: {
type: String,
default: "",
},
});
let calendarsRef = ref(null);
function Confirm(e) {
console.log(e);
emit("update:time", e.fulldate);
// emit("update:endTime", e.range.after);
}
const title = computed(() => {
return props.time;
});
</script>
<style lang="scss" scoped></style>

View File

@@ -61,6 +61,7 @@ export function usePaging<T>(options: Options) {
pager.loading = "loadmore";
}
}else{
toast(res.message);
pager.loading = "loadmore";
}
return Promise.resolve(res);

View File

@@ -45,6 +45,34 @@
"style": {
"navigationBarTitleText": "搜索项目监控"
}
},
{
"path": "pages/monitor_client/index",
"style": {
"navigationBarTitleText": "监控-客户端信息",
"enablePullDownRefresh": true,
"onReachBottomDistance": 100
}
},
{
"path": "pages/monitor_client/details",
"style": {
"navigationBarTitleText": "监控-客户端信息详情",
"enablePullDownRefresh": true
}
},
{
"path": "pages/monitor_client/edit",
"style": {
"navigationBarTitleText": "编辑监控-客户端信息"
}
},
{
"path": "pages/monitor_client/search",
"style": {
"navigationBarTitleText": "搜索监控-客户端信息"
}
}

View File

@@ -38,6 +38,11 @@
path: "/pages/monitor_project/index",
title: "项目监控",
},
{
icon: "/static/index/equipment.png",
path: "/pages/monitor_client/index",
title: "项目用户",
},
{

View File

@@ -0,0 +1,114 @@
<template>
<view class="page-content">
<uv-form labelPosition="left" :model="form">
<uv-form-item label="项目key" prop="projectKey" borderBottom>
{{form.projectKey}}
</uv-form-item>
<uv-form-item label="sdk生成的客户端id" prop="clientId" borderBottom>
{{form.clientId}}
</uv-form-item>
<uv-form-item label="用户id" prop="userId" borderBottom>
{{form.userId}}
</uv-form-item>
<uv-form-item label="系统" prop="os" borderBottom>
{{form.os}}
</uv-form-item>
<uv-form-item label="浏览器" prop="browser" borderBottom>
{{form.browser}}
</uv-form-item>
<uv-form-item label="城市" prop="city" borderBottom>
{{form.city}}
</uv-form-item>
<uv-form-item label="屏幕" prop="width" borderBottom>
{{form.width}}
</uv-form-item>
<uv-form-item label="屏幕高度" prop="height" borderBottom>
{{form.height}}
</uv-form-item>
<uv-form-item label="ua记录" prop="ua" borderBottom>
{{form.ua}}
</uv-form-item>
<uv-form-item label="创建时间" prop="createTime" borderBottom>
{{form.createTime}}
</uv-form-item>
<uv-form-item label="更新时间" prop="clientTime" borderBottom>
{{form.clientTime}}
</uv-form-item>
</uv-form>
<uv-button
v-if="$perms('admin:monitor_client:edit')"
type="primary"
text="编辑"
customStyle="margin: 40rpx 0"
@click="edit"
></uv-button>
</view>
</template>
<script setup lang="ts">
import {ref} from "vue";
import { onLoad,onShow } from "@dcloudio/uni-app";
import { useDictData } from "@/hooks/useDictOptions";
import { monitor_client_detail } from "@/api/monitor_client";
import {
toast,
alert,
toPath
} from "@/utils/utils";
let form = ref({
id: "",
projectKey: "",
clientId: "",
userId: "",
os: "",
browser: "",
city: "",
width: "",
height: "",
ua: "",
createTime: "",
clientTime: "",
});
onLoad((e) => {
console.log("onLoad", e);
getDetails(e.id);
});
onShow((e) => {
if (form.value?.id) {
getDetails(form.value.id);
}
});
onPullDownRefresh(() => {
getDetails(form.value.id);
});
function getDetails(id: number | string) {
monitor_client_detail(id).then((res) => {
uni.stopPullDownRefresh();
if (res.code == 200) {
if (res?.data) {
form.value = res?.data
}
} else {
toast(res.message);
}
})
.catch((err) => {
uni.stopPullDownRefresh();
toast(err.message||"网络错误");
});
}
function edit() {
toPath("/pages/monitor_client/edit", { id: form.value.id });
}
</script>
<style lang="scss" scoped>
.page-content {
padding: 10rpx 20rpx 300rpx;
}
</style>

View File

@@ -0,0 +1,191 @@
<template>
<view class="page-content">
<uv-form
labelPosition="left"
:model="form"
:rules="formRules"
ref="formRef"
>
<uv-form-item label="sdk生成的客户端id" prop="clientId" borderBottom>
<uv-input v-model="form.clientId" border="surround"></uv-input>
</uv-form-item>
<uv-form-item label="用户id" prop="userId" borderBottom>
<uv-input v-model="form.userId" border="surround"></uv-input>
</uv-form-item>
<uv-form-item label="系统" prop="os" borderBottom>
<uv-input v-model="form.os" border="surround"></uv-input>
</uv-form-item>
<uv-form-item label="浏览器" prop="browser" borderBottom>
<uv-input v-model="form.browser" border="surround"></uv-input>
</uv-form-item>
<uv-form-item label="城市" prop="city" borderBottom>
<uv-input v-model="form.city" border="surround"></uv-input>
</uv-form-item>
<uv-form-item label="屏幕" prop="width" borderBottom>
<uv-input v-model="form.width" border="surround"></uv-input>
</uv-form-item>
<uv-form-item label="屏幕高度" prop="height" borderBottom>
<uv-input v-model="form.height" border="surround"></uv-input>
</uv-form-item>
<uv-form-item label="ua记录" prop="ua" borderBottom>
<uv-input v-model="form.ua" border="surround"></uv-input>
</uv-form-item>
<uv-form-item label="更新时间" prop="clientTime" borderBottom>
<x-date v-model:time="form.clientTime"></x-date>
</uv-form-item>
<uv-button
type="primary"
text="提交"
customStyle="margin: 40rpx 0"
@click="submit"
></uv-button>
</uv-form>
</view>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import {
monitor_client_detail,
monitor_client_edit,
monitor_client_add,
} from "@/api/monitor_client";
import type { type_monitor_client_edit } from "@/api/monitor_client";
import { toast, alert } from "@/utils/utils";
import { useDictData } from "@/hooks/useDictOptions";
let formRef = ref();
let form = ref<type_monitor_client_edit>({
id: null,
clientId: "",
userId: "",
os: "",
browser: "",
city: "",
width: null,
height: null,
ua: "",
clientTime: "",
});
const formRules = {
clientId: [
{
required: true,
message: "请输入sdk生成的客户端id",
trigger: ["blur"],
},
],
userId: [
{
required: true,
message: "请输入用户id",
trigger: ["blur"],
},
],
os: [
{
required: true,
message: "请输入系统",
trigger: ["blur"],
},
],
browser: [
{
required: true,
message: "请输入浏览器",
trigger: ["blur"],
},
],
city: [
{
required: true,
message: "请输入城市",
trigger: ["blur"],
},
],
width: [
{
required: true,
message: "请输入屏幕",
trigger: ["blur"],
},
],
height: [
{
required: true,
message: "请输入屏幕高度",
trigger: ["blur"],
},
],
ua: [
{
required: true,
message: "请输入ua记录",
trigger: ["blur"],
},
],
clientTime: [
{
required: true,
message: "请选择更新时间",
trigger: ["blur"],
},
],
};
onLoad((e) => {
console.log("onLoad", e);
if (e.id) {
getDetails(e.id);
}
});
function getDetails(id) {
monitor_client_detail(id)
.then((res) => {
if (res.code == 200) {
if (res?.data) {
form.value = res?.data;
}
} else {
toast(res.message);
}
})
.catch((err) => {
toast(err.message || "网络错误");
});
}
function submit() {
console.log("submit", form.value);
formRef.value.validate().then(() => {
if (form.value.id) {
monitor_client_edit(form.value).then((res) => {
if (res.code == 200) {
toast("编辑成功");
getDetails(form.value?.id);
} else {
toast(res.message);
}
});
} else {
monitor_client_add(form.value).then((res) => {
if (res.code == 200) {
toast("添加成功");
uni.navigateBack();
} else {
toast(res.message);
}
});
}
});
}
</script>
<style lang="scss" scoped>
.page-content {
padding: 10rpx 20rpx 300rpx;
}
</style>

View File

@@ -0,0 +1,135 @@
<template>
<view>
<!--
<uv-sticky :customNavHeight="0" bgColor="#fff">
<uv-status-bar></uv-status-bar>
<uv-navbar
leftText=""
:safeAreaInsetTop="false"
:fixed="false"
title="监控-客户端信息"
autoBack
>
<template v-slot:right>
<uv-icon v-if="!fromSearch" name="search" size="24" @click="moreSearch"></uv-icon>
</template>
</uv-navbar>
</uv-sticky>
-->
<uv-list>
<uv-list-item
v-for="item of pager.lists"
:key="item.id"
clickable
show-arrow
:title="item.id"
:right-text="item.id"
@click="toDetails(item)"
></uv-list-item>
</uv-list>
<wd-fab v-model:active="activeFab" :draggable="true">
<wd-button v-if="!fromSearch" custom-class="fab-button" type="primary" round @click="moreSearch" >
<wd-icon name="search" size="20px"></wd-icon>
</wd-button>
<wd-button v-if="$perms('admin:monitor_client:add')" custom-class="fab-button" type="primary" round @click="add">
<wd-icon name="add" size="20px"></wd-icon>
</wd-button>
</wd-fab>
<uv-back-top :scroll-top="scrollTop"></uv-back-top>
<uv-empty v-if="pager.loading =='nomore'&&pager.lists.length == 0" marginTop="150" mode="data"></uv-empty>
<uv-loading-page
:loading="pager.pageNo == 1 && pager.loading == 'loading'"
loading-text="加载中..."
font-size="24rpx"
></uv-loading-page>
<uv-load-more
v-if="pager.lists.length > 0"
:status="pager.loading"
:loading-text="pager.loadingText"
:loadmore-text="pager.loadmoreText"
:nomore-text="pager.nomoreText"
@loadmore="NextPage"
/>
</view>
</template>
<script setup lang="ts">
import { reactive, ref } from "vue";
import {
onLoad,
onPullDownRefresh,
onReachBottom,
onPageScroll,
} from "@dcloudio/uni-app";
import { monitor_client_list } from "@/api/monitor_client";
import type { type_monitor_client,type_monitor_client_query } from "@/api/monitor_client";
import { usePaging } from "@/hooks/usePaging";
import { toPath } from "@/utils/utils";
const queryParams = reactive<type_monitor_client_query>({
projectKey: '',
clientId: '',
userId: '',
os: '',
browser: '',
city: '',
width: null,
height: null,
ua: '',
createTimeStart: '',
createTimeEnd: '',
clientTimeStart: '',
clientTimeEnd: '',
});
let activeFab = ref(false);
let fromSearch=ref(false);
onLoad((e) => {
console.log("monitor_client onLoad", e);
if (e) {
for (const key in e) {
if (Object.hasOwnProperty.call(e, key)) {
fromSearch.value = true;
queryParams[key] = e[key];
}
}
}
getLists();
});
const { pager, getLists, NextPage, resetPage, resetParams } = usePaging<type_monitor_client>({
fetchFun: monitor_client_list,
params: queryParams,
});
let scrollTop = ref(0);
onPageScroll((e) => {
scrollTop.value = e.scrollTop;
});
onPullDownRefresh(() => {
resetPage();
});
onReachBottom(() => {
NextPage();
});
function toDetails(item) {
toPath("/pages/monitor_client/details", { id: item.id });
}
function moreSearch() {
toPath("/pages/monitor_client/search");
}
function add() {
toPath("/pages/monitor_client/edit");
}
</script>
<style lang="scss" scoped>
:deep(.fab-button) {
min-width: auto !important;
box-sizing: border-box;
width: 40px !important;
height: 40px !important;
border-radius: 40px !important;
margin: 8rpx;
}
</style>

View File

@@ -0,0 +1,32 @@
// 请将pages里的数据手动合并到根目录下pages.json中
{
"pages": [
{
"path": "pages/monitor_client/index",
"style": {
"navigationBarTitleText": "监控-客户端信息",
"enablePullDownRefresh": true,
"onReachBottomDistance": 100
}
},
{
"path": "pages/monitor_client/details",
"style": {
"navigationBarTitleText": "监控-客户端信息详情",
"enablePullDownRefresh": true
}
},
{
"path": "pages/monitor_client/edit",
"style": {
"navigationBarTitleText": "编辑监控-客户端信息"
}
},
{
"path": "pages/monitor_client/search",
"style": {
"navigationBarTitleText": "搜索监控-客户端信息"
}
}
]
}

View File

@@ -0,0 +1,99 @@
<template>
<view class="page-content">
<uv-form labelPosition="left" labelWidth="80" :model="form">
<uv-form-item label="项目key" prop="projectKey" borderBottom>
</uv-form-item>
<uv-form-item label="sdk生成的客户端id" prop="clientId" borderBottom>
<uv-input v-model="form.clientId"> </uv-input>
</uv-form-item>
<uv-form-item label="用户id" prop="userId" borderBottom>
<uv-input v-model="form.userId"> </uv-input>
</uv-form-item>
<uv-form-item label="系统" prop="os" borderBottom>
<uv-input v-model="form.os"> </uv-input>
</uv-form-item>
<uv-form-item label="浏览器" prop="browser" borderBottom>
<uv-input v-model="form.browser"> </uv-input>
</uv-form-item>
<uv-form-item label="城市" prop="city" borderBottom>
<uv-input v-model="form.city"> </uv-input>
</uv-form-item>
<uv-form-item label="屏幕" prop="width" borderBottom>
<uv-input v-model="form.width"> </uv-input>
</uv-form-item>
<uv-form-item label="屏幕高度" prop="height" borderBottom>
<uv-input v-model="form.height"> </uv-input>
</uv-form-item>
<uv-form-item label="ua记录" prop="ua" borderBottom>
<uv-input v-model="form.ua"> </uv-input>
</uv-form-item>
<uv-form-item label="创建时间" prop="createTime" borderBottom>
<x-date-range v-model:startTime="form.createTimeStart"
v-model:endTime="form.createTimeEnd"></x-date-range>
</uv-form-item>
<uv-form-item label="更新时间" prop="clientTime" borderBottom>
<x-date-range v-model:startTime="form.clientTimeStart"
v-model:endTime="form.clientTimeEnd"></x-date-range>
</uv-form-item>
<uv-button type="primary" text="搜索" customStyle="margin-top: 20rpx" @click="submit"></uv-button>
</uv-form>
</view>
</template>
<script setup lang="ts">
import {
onLoad
} from "@dcloudio/uni-app";
import {
reactive,
ref,
computed
} from "vue";
import {
toPath,
toast,
clearObjEmpty
} from "@/utils/utils";
import {
useDictData
} from "@/hooks/useDictOptions";
import xDateRange from "@/components/x-date-range/x-date-range.vue";
import type {type_monitor_client_query} from "@/api/monitor_project";
let form = ref<type_monitor_client_query>({
projectKey: '',
clientId: '',
userId: '',
os: '',
browser: '',
city: '',
width: '',
height: '',
ua: '',
createTimeStart: '',
createTimeEnd: '',
clientTimeStart: '',
clientTimeEnd: '',
});
function submit() {
console.log("submit", form.value);
const search = clearObjEmpty(form.value);
if (Object.keys(search).length === 0) {
return toast("请输入查询条件");
}
toPath("/pages/monitor_client/index", search);
}
</script>
<style lang="scss" scoped>
.page-content {
padding: 10rpx 20rpx 300rpx;
}
</style>