优化代码生成

This commit is contained in:
xiangheng
2024-06-17 21:29:38 +08:00
parent cdb3253b02
commit a700a39992
18 changed files with 329 additions and 272 deletions

View File

@@ -1,5 +1,6 @@
{ {
"cSpell.words": [ "cSpell.words": [
"dcloudio",
"excelize", "excelize",
"fontsize", "fontsize",
"freetype", "freetype",

View File

@@ -25,9 +25,9 @@ admin:{{{.ModuleName }}}:detail
admin:{{{.ModuleName }}}:ExportFile admin:{{{.ModuleName }}}:ExportFile
admin:{{{.ModuleName }}}:ImportFile admin:{{{.ModuleName }}}:ImportFile
// 列表 // 列表-先添加菜单获取菜单id
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, paths, component, is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'C', '{{{ .FunctionName }}}', '/{{{ .ModuleName }}}/index', '{{{ .ModuleName }}}/index', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, paths, component, is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'C', '{{{ .FunctionName }}}', '/{{{ .ModuleName }}}/index', '{{{ .ModuleName }}}/index', 0, 1, 0, now(), now());
按钮 按钮-替换pid参数为菜单id
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}添加','admin:{{{ .ModuleName }}}:add', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}添加','admin:{{{ .ModuleName }}}:add', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}编辑','admin:{{{ .ModuleName }}}:edit', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}编辑','admin:{{{ .ModuleName }}}:edit', 0, 1, 0, now(), now());
INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}删除','admin:{{{ .ModuleName }}}:del', 0, 1, 0, now(), now()); INSERT INTO x_system_auth_menu (pid, menu_type, menu_name, perms,is_cache, is_show, is_disable, create_time, update_time) VALUES (0, 'A', '{{{ .FunctionName }}}删除','admin:{{{ .ModuleName }}}:del', 0, 1, 0, now(), now());

View File

@@ -1,11 +1,5 @@
<template> <template>
<view class="page-content"> <view class="page-content">
<uv-navbar leftText="" :placeholder="true" title="{{{.FunctionName}}}详情" autoBack>
<template v-slot:right>
<uv-icon name="edit-pen" size="20" @click="edit"></uv-icon>
</template>
</uv-navbar>
<uv-form labelPosition="left" :model="form"> <uv-form labelPosition="left" :model="form">
{{{- range .Columns }}} {{{- range .Columns }}}
{{{- if .IsList }}} {{{- if .IsList }}}
@@ -25,7 +19,7 @@
v-if="$perms('admin:{{{ .ModuleName }}}:edit')" v-if="$perms('admin:{{{ .ModuleName }}}:edit')"
type="primary" type="primary"
text="编辑" text="编辑"
customStyle="margin-top: 20rpx" customStyle="margin: 40rpx 0"
@click="edit" @click="edit"
></uv-button> ></uv-button>

View File

@@ -21,7 +21,7 @@
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
<uv-button type="primary" text="提交" customStyle="margin-top: 20rpx" <uv-button type="primary" text="提交" customStyle="margin: 40rpx 0"
@click="submit"></uv-button> @click="submit"></uv-button>
</uv-form> </uv-form>
</view> </view>
@@ -34,7 +34,8 @@
} from "@dcloudio/uni-app"; } from "@dcloudio/uni-app";
import { import {
{{{ .ModuleName }}}_detail, {{{ .ModuleName }}}_detail,
{{{ .ModuleName }}}_edit {{{ .ModuleName }}}_edit,
{{{ .ModuleName }}}_add
} from "@/api/{{{ .ModuleName }}}"; } from "@/api/{{{ .ModuleName }}}";
import type { type_{{{ .ModuleName }}}_edit } from "@/api/{{{ .ModuleName }}}"; import type { type_{{{ .ModuleName }}}_edit } from "@/api/{{{ .ModuleName }}}";
@@ -81,7 +82,9 @@
} }
onLoad((e) => { onLoad((e) => {
console.log("onLoad", e); console.log("onLoad", e);
getDetails(e.id); if (e.id) {
getDetails(e.id);
}
}); });
@@ -112,15 +115,26 @@
function submit() { function submit() {
console.log("submit", form.value); console.log("submit", form.value);
formRef.value.validate().then(() => { formRef.value.validate().then(() => {
{{{ .ModuleName }}}_edit(form.value).then((res) => { if (form.value.id) {
if (res.code == 200) { {{{ .ModuleName }}}_edit(form.value).then((res) => {
toast("编辑成功"); if (res.code == 200) {
toast("编辑成功");
getDetails(form.value?.id); getDetails(form.value?.id);
} else { } else {
toast(res.message); toast(res.message);
} }
}); });
}else{
{{{ .ModuleName }}}_add(form.value).then((res) => {
if (res.code == 200) {
toast("添加成功");
uni.navigateBack();
} else {
toast(res.message);
}
});
}
}) })
} }
</script> </script>

View File

@@ -1,6 +1,6 @@
<template> <template>
<view> <view>
<!--
<uv-sticky :customNavHeight="0" bgColor="#fff"> <uv-sticky :customNavHeight="0" bgColor="#fff">
<uv-status-bar></uv-status-bar> <uv-status-bar></uv-status-bar>
<uv-navbar <uv-navbar
@@ -16,7 +16,7 @@
</uv-navbar> </uv-navbar>
</uv-sticky> </uv-sticky>
-->
<uv-list> <uv-list>
<uv-list-item <uv-list-item
v-for="item of pager.lists" v-for="item of pager.lists"
@@ -24,12 +24,18 @@
clickable clickable
show-arrow show-arrow
:title="item.id" :title="item.id"
:note="item.id"
:right-text="item.id" :right-text="item.id"
@click="toDetails(item)" @click="toDetails(item)"
></uv-list-item> ></uv-list-item>
</uv-list> </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:{{{ .ModuleName }}}: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-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-empty v-if="pager.loading =='nomore'&&pager.lists.length == 0" marginTop="150" mode="data"></uv-empty>
@@ -74,6 +80,7 @@ const queryParams = reactive<type_{{{.ModuleName}}}_query>({
{{{- end }}} {{{- end }}}
{{{- end }}} {{{- end }}}
}); });
let activeFab = ref(false);
let fromSearch=ref(false); let fromSearch=ref(false);
onLoad((e) => { onLoad((e) => {
console.log("{{{ .ModuleName }}} onLoad", e); console.log("{{{ .ModuleName }}} onLoad", e);
@@ -108,8 +115,18 @@ function toDetails(item) {
function moreSearch() { function moreSearch() {
toPath("/pages/{{{ .ModuleName }}}/search"); toPath("/pages/{{{ .ModuleName }}}/search");
} }
function add() {
toPath("/pages/{{{ .ModuleName }}}/edit");
}
</script> </script>
<style lang="scss" scoped> <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> </style>

View File

@@ -6,16 +6,14 @@
"style": { "style": {
"navigationBarTitleText": "{{{.FunctionName}}}", "navigationBarTitleText": "{{{.FunctionName}}}",
"enablePullDownRefresh": true, "enablePullDownRefresh": true,
"onReachBottomDistance": 100, "onReachBottomDistance": 100
"navigationStyle": "custom"
} }
}, },
{ {
"path": "pages/{{{ .ModuleName }}}/details", "path": "pages/{{{ .ModuleName }}}/details",
"style": { "style": {
"navigationBarTitleText": "{{{.FunctionName}}}详情", "navigationBarTitleText": "{{{.FunctionName}}}详情",
"enablePullDownRefresh": true, "enablePullDownRefresh": true
"navigationStyle": "custom"
} }
}, },
{ {

View File

@@ -43,7 +43,7 @@ func (adminSrv systemAuthAdminService) Self(adminId uint) (res SystemAuthAdminSe
// 管理员信息 // 管理员信息
var sysAdmin system_model.SystemAuthAdmin var sysAdmin system_model.SystemAuthAdmin
err := adminSrv.db.Where("id = ? AND is_delete = ?", adminId, 0).Limit(1).First(&sysAdmin).Error err := adminSrv.db.Where("id = ? AND is_delete = ?", adminId, 0).Limit(1).First(&sysAdmin).Error
if e = response.CheckErr(err, "Self First err"); e != nil { if e = response.CheckErr(err, "获取用户信息失败"); e != nil {
return return
} }
// 角色权限 // 角色权限
@@ -59,18 +59,21 @@ func (adminSrv systemAuthAdminService) Self(adminId uint) (res SystemAuthAdminSe
err := adminSrv.db.Where( err := adminSrv.db.Where(
"id in ? AND is_disable = ? AND menu_type in ?", menuIds, 0, []string{"C", "A"}).Order( "id in ? AND is_disable = ? AND menu_type in ?", menuIds, 0, []string{"C", "A"}).Order(
"menu_sort, id").Find(&menus).Error "menu_sort, id").Find(&menus).Error
if e = response.CheckErr(err, "Self SystemAuthMenu Find err"); e != nil { if e = response.CheckErr(err, "查找权限失败"); e != nil {
return return
} }
if len(menus) > 0 { if len(menus) > 0 {
for _, v := range menus { for _, v := range menus {
if v.Perms == "" {
continue
}
auths = append(auths, strings.Trim(v.Perms, " ")) auths = append(auths, strings.Trim(v.Perms, " "))
} }
} }
} }
if len(auths) > 0 { // if len(auths) > 0 {
auths = append(auths, "") // auths = append(auths, "")
} // }
} else { } else {
auths = append(auths, "*") auths = append(auths, "*")
} }

View File

@@ -66,7 +66,7 @@ func (service systemAuthPermService) CacheRoleMenusByRoleId(roleId uint) (e erro
err = service.db.Where( err = service.db.Where(
"is_disable = ? and id in ? and menu_type in ?", 0, menuIds, []string{"C", "A"}).Order( "is_disable = ? and id in ? and menu_type in ?", 0, menuIds, []string{"C", "A"}).Order(
"menu_sort, id").Find(&menus).Error "menu_sort, id").Find(&menus).Error
if e = response.CheckErr(err, "CacheRoleMenusByRoleId Find menus err"); e != nil { if e = response.CheckErr(err, "查找角色菜单失败"); e != nil {
return return
} }
var menuArray []string var menuArray []string

View File

@@ -143,12 +143,14 @@ func (roleSrv systemAuthRoleService) Edit(editReq SystemAuthRoleEditReq) (e erro
err = roleSrv.db.Transaction(func(tx *gorm.DB) error { err = roleSrv.db.Transaction(func(tx *gorm.DB) error {
txErr := tx.Model(&role).Updates(roleMap).Error txErr := tx.Model(&role).Updates(roleMap).Error
var te error var te error
if te = response.CheckErr(txErr, "Edit Updates in tx err"); te != nil { if te = response.CheckErr(txErr, "编辑角色失败"); te != nil {
return te return te
} }
// 删除角色菜单
if te = PermService.BatchDeleteByRoleId(editReq.ID, tx); te != nil { if te = PermService.BatchDeleteByRoleId(editReq.ID, tx); te != nil {
return te return te
} }
// 重新保存角色菜单
if te = PermService.BatchSaveByMenuIds(editReq.ID, editReq.MenuIds, tx); te != nil { if te = PermService.BatchSaveByMenuIds(editReq.ID, editReq.MenuIds, tx); te != nil {
return te return te
} }

View File

@@ -2,7 +2,7 @@
"version" : "1.0", "version" : "1.0",
"configurations" : [ "configurations" : [
{ {
"playground" : "standard", "playground" : "custom",
"type" : "uni-app:app-android" "type" : "uni-app:app-android"
}, },
{ {

View File

@@ -1,14 +1,16 @@
<template> <template>
<uv-input <!-- 在微信小程序readonly后无法click,所以套一层view -->
:modelValue="selectItem?.[props.labelKey]" <view style="flex: 1" @click="openPicker">
placeholder="请选择" <uv-input
readonly :modelValue="selectItem?.[props.labelKey]"
@click="openPicker" placeholder="请选择"
> readonly
</uv-input> >
</uv-input>
</view>
<uv-picker <uv-picker
ref="picker" ref="pickerRef"
:columns="columns" :columns="columns"
:keyName="props.labelKey" :keyName="props.labelKey"
:defaultIndex="pickerIndex" :defaultIndex="pickerIndex"
@@ -19,7 +21,7 @@
<script setup> <script setup>
import { ref, onMounted, computed, watch } from "vue"; import { ref, onMounted, computed, watch } from "vue";
const emit = defineEmits(["update:modelValue"]) const emit = defineEmits(["update:modelValue"]);
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
@@ -40,18 +42,18 @@ const props = defineProps({
}, },
}); });
const model = computed({ const model = computed({
get() { get() {
return props.modelValue return props.modelValue;
}, },
set(value) { set(value) {
emit('update:modelValue', value) emit("update:modelValue", value);
} },
}) });
const columns = computed(() => { const columns = computed(() => {
return [props.columns]; return [props.columns];
}); });
const picker = ref(null); const pickerRef = ref(null);
// const model = defineModel('modelValue'); // const model = defineModel('modelValue');
const pickerIndex = ref([0]); const pickerIndex = ref([0]);
@@ -59,7 +61,8 @@ const pickerIndex = ref([0]);
const selectItem = ref({}); const selectItem = ref({});
function openPicker() { function openPicker() {
picker.value.open();
pickerRef.value.open();
} }
function handleConfirm(e) { function handleConfirm(e) {
// debugger; // debugger;
@@ -73,7 +76,7 @@ function handleConfirm(e) {
} }
} }
function updateSelectItem() { function updateSelectItem() {
console.log("updateSelectItem", model.value, props.columns);
if (!model.value) { if (!model.value) {
pickerIndex.value = [0]; pickerIndex.value = [0];
selectItem.value = {}; selectItem.value = {};
@@ -101,13 +104,13 @@ function updateSelectItem() {
} }
} }
onMounted(() => { onMounted(() => {
console.log("onMounted");
updateSelectItem(); updateSelectItem();
}); });
watch( watch(
() => [model.value, props.columns], () => [model.value, props.columns],
(newVal) => { (newVal) => {
console.log("watch", newVal);
updateSelectItem(); updateSelectItem();
} }
); );

View File

@@ -22,8 +22,8 @@
"style": { "style": {
"navigationBarTitleText": "项目监控", "navigationBarTitleText": "项目监控",
"enablePullDownRefresh": true, "enablePullDownRefresh": true,
"onReachBottomDistance": 100, "onReachBottomDistance": 100
"navigationStyle": "custom"
} }
}, },
@@ -31,8 +31,7 @@
"path": "pages/monitor_project/details", "path": "pages/monitor_project/details",
"style": { "style": {
"navigationBarTitleText": "项目监控详情", "navigationBarTitleText": "项目监控详情",
"enablePullDownRefresh": true, "enablePullDownRefresh": true
"navigationStyle": "custom"
} }
}, },
{ {

View File

@@ -1,109 +1,91 @@
<template> <template>
<view class="page-content"> <view class="page-content">
<uv-navbar leftText="" :placeholder="true" title="监控项目详情" autoBack>
<template v-slot:right>
<uv-icon name="edit-pen" size="20" @click="edit"></uv-icon>
</template>
</uv-navbar>
<uv-form labelPosition="left" labelWidth="80" :model="form">
<uv-form-item label="项目uuid" prop="projectKey" borderBottom>
{{form.projectKey}}
</uv-form-item>
<uv-form-item label="项目名称" prop="projectName" borderBottom>
{{form.projectName}}
</uv-form-item>
<uv-form-item label="项目类型" prop="projectType" borderBottom>
{{form.projectType}}
</uv-form-item>
<uv-form-item label="创建时间" prop="createTime" borderBottom>
{{form.createTime}}
</uv-form-item>
<uv-form-item label="更新时间" prop="updateTime" borderBottom>
{{form.updateTime}}
</uv-form-item>
</uv-form>
<uv-button
v-if="$perms('admin:monitor_project:edit')"
type="primary"
text="编辑"
customStyle="margin-top: 20rpx"
@click="edit"
></uv-button>
</view> <uv-form labelPosition="left" labelWidth="80" :model="form">
<uv-form-item label="项目uuid" prop="projectKey" borderBottom>
{{ form.projectKey }}
</uv-form-item>
<uv-form-item label="项目名称" prop="projectName" borderBottom>
{{ form.projectName }}
</uv-form-item>
<uv-form-item label="项目类型" prop="projectType" borderBottom>
{{ form.projectType }}
</uv-form-item>
<uv-form-item label="创建时间" prop="createTime" borderBottom>
{{ form.createTime }}
</uv-form-item>
<uv-form-item label="更新时间" prop="updateTime" borderBottom>
{{ form.updateTime }}
</uv-form-item>
</uv-form>
<uv-button
v-if="$perms('admin:monitor_project:edit')"
type="primary"
text="编辑"
customStyle="margin: 40rpx 0"
@click="edit"
></uv-button>
</view>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { import { reactive, ref, computed } from "vue";
reactive, import { onLoad, onShow, onPullDownRefresh } from "@dcloudio/uni-app";
ref,
computed
} from "vue";
import {
onLoad,
onShow,
onPullDownRefresh
} from "@dcloudio/uni-app";
import { import { useDictData } from "@/hooks/useDictOptions";
useDictData import { monitor_project_detail } from "@/api/monitor_project";
} from "@/hooks/useDictOptions"; import type { type_monitor_project } from "@/api/monitor_project";
import {
monitor_project_detail
} from "@/api/monitor_project";
import type {type_monitor_project} from "@/api/monitor_project";
import { import { toast, alert, toPath } from "@/utils/utils";
toast,
alert,
toPath
} from "@/utils/utils";
let form = ref<type_monitor_project>({ let form = ref<type_monitor_project>({
id: 0, id: 0,
projectKey: "", projectKey: "",
projectName: "", projectName: "",
projectType: "", projectType: "",
createTime: "", createTime: "",
updateTime: "", updateTime: "",
}); });
onLoad((e) => { onLoad((e) => {
console.log("onLoad", e); console.log("onLoad", e);
getDetails(e.id); if (e.id) {
}); getDetails(e.id);
onShow((e) => { }
if (form.value?.id) { });
getDetails(form.value.id); onShow((e) => {
} if (form.value?.id) {
}); getDetails(form.value.id);
onPullDownRefresh(() => { }
getDetails(form.value.id); });
}); onPullDownRefresh(() => {
function getDetails(id) { getDetails(form.value.id);
monitor_project_detail(id).then((res) => { });
uni.stopPullDownRefresh(); function getDetails(id) {
if (res.code == 200) { monitor_project_detail(id)
if (res.data) { .then((res) => {
form.value = res?.data uni.stopPullDownRefresh();
} if (res.code == 200) {
} else { if (res.data) {
toast(res.message); form.value = res?.data;
} }
}) } else {
.catch((err) => { toast(res.message);
uni.stopPullDownRefresh(); }
toast(err.message||"网络错误"); })
}); .catch((err) => {
} uni.stopPullDownRefresh();
toast(err.message || "网络错误");
});
}
function edit() { function edit() {
toPath("/pages/monitor_project/edit", { id: form.value.id }); toPath("/pages/monitor_project/edit", { id: form.value.id });
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.page-content { .page-content {
padding: 10rpx 20rpx 300rpx; padding: 10rpx 20rpx 300rpx;
} }
</style> </style>

View File

@@ -1,110 +1,132 @@
<template> <template>
<view class="page-content"> <view class="page-content">
<uv-form labelPosition="left" labelWidth="80" :model="form" :rules="formRules" ref="formRef"> <uv-form
labelPosition="left"
labelWidth="80"
:model="form"
:rules="formRules"
ref="formRef"
>
<uv-form-item label="项目uuid" prop="projectKey" borderBottom>
<uv-input v-model="form.projectKey" border="surround"></uv-input>
</uv-form-item>
<uv-form-item label="项目名称" prop="projectName" borderBottom>
<uv-input v-model="form.projectName" border="surround"></uv-input>
</uv-form-item>
<uv-form-item label="项目类型" prop="projectType" borderBottom>
<x-picker
v-model="form.projectType"
valueKey="value"
labelKey="name"
:columns="dictData.project_type"
></x-picker>
</uv-form-item>
<uv-form-item label="项目uuid" prop="projectKey" borderBottom> <uv-button
<uv-input v-model="form.projectKey" border="surround"></uv-input> type="primary"
</uv-form-item> text="提交"
<uv-form-item label="项目名称" prop="projectName" borderBottom> customStyle="margin: 40rpx 0"
<uv-input v-model="form.projectName" border="surround"></uv-input> @click="submit"
</uv-form-item> ></uv-button>
<uv-form-item label="项目类型" prop="projectType" borderBottom> </uv-form>
<x-picker v-model="form.projectType" valueKey="value" labelKey="name" </view>
:columns="dictData.project_type"></x-picker>
</uv-form-item>
<uv-button type="primary" text="提交" customStyle="margin-top: 20rpx" @click="submit"></uv-button>
</uv-form>
</view>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { import { reactive, ref, computed } from "vue";
reactive, import { onLoad } from "@dcloudio/uni-app";
ref, import {
computed monitor_project_detail,
} from "vue"; monitor_project_edit,
import { monitor_project_add,
onLoad } from "@/api/monitor_project";
} from "@dcloudio/uni-app"; import type { type_monitor_project_edit } from "@/api/monitor_project";
import { import { toast, alert } from "@/utils/utils";
monitor_project_detail, import { useDictData } from "@/hooks/useDictOptions";
monitor_project_edit, const { dictData } = useDictData(["project_type"]);
} from "@/api/monitor_project"; let formRef = ref();
import type {type_monitor_project_edit} from "@/api/monitor_project"; let form = ref<type_monitor_project_edit>({
import { id: null,
toast, projectKey: "",
alert projectName: "",
} from "@/utils/utils"; projectType: "",
import { });
useDictData const formRules = {
} from "@/hooks/useDictOptions"; projectKey: [
const { {
dictData required: true,
} = useDictData(['project_type']) message: "请输入项目uuid",
let formRef = ref(); trigger: ["blur"],
let form = ref<type_monitor_project_edit>({ },
id: null, ],
projectKey: "", projectName: [
projectName: "", {
projectType: "", required: true,
}); message: "请输入项目名称",
const formRules = { trigger: ["blur"],
projectKey: [{ },
required: true, ],
message: "请输入项目uuid", projectType: [
trigger: ["blur"], {
}, ], required: true,
projectName: [{ message: "请选择项目类型",
required: true, trigger: ["blur"],
message: "请输入项目名称", },
trigger: ["blur"], ],
}, ], };
projectType: [{ onLoad((e) => {
required: true, console.log("onLoad", e);
message: "请选择项目类型",
trigger: ["blur"],
}, ],
};
onLoad((e) => {
console.log("onLoad", e);
getDetails(e.id);
});
function getDetails(id) { if (e.id) {
monitor_project_detail(id) getDetails(e.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() { function getDetails(id) {
console.log("submit", form); monitor_project_detail(id)
formRef.value.validate().then(() => { .then((res) => {
monitor_project_edit(form.value).then((res) => { if (res.code == 200) {
if (res.code == 200) { if (res.data) {
toast("编辑成功"); form.value = res?.data;
}
} else {
toast(res.message);
}
})
.catch((err) => {
toast(err.message || "网络错误");
});
}
getDetails(form.value?.id); function submit() {
} else { console.log("submit", form);
toast(res.message); formRef.value.validate().then(() => {
} if (form.value.id) {
}); monitor_project_edit(form.value).then((res) => {
}); if (res.code == 200) {
} toast("编辑成功");
getDetails(form.value?.id);
} else {
toast(res.message);
}
});
} else {
monitor_project_add(form.value).then((res) => {
if (res.code == 200) {
toast("添加成功");
uni.navigateBack();
} else {
toast(res.message);
}
});
}
});
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.page-content { .page-content {
padding: 10rpx 20rpx 300rpx; padding: 10rpx 20rpx 300rpx;
} }
</style> </style>

View File

@@ -1,7 +1,7 @@
<template> <template>
<view> <view>
<uv-sticky :customNavHeight="0" bgColor="#fff"> <!-- <uv-sticky :customNavHeight="0" bgColor="#fff">
<uv-status-bar></uv-status-bar> <uv-status-bar></uv-status-bar>
<uv-navbar <uv-navbar
leftText="" leftText=""
@@ -15,7 +15,7 @@
</template> </template>
</uv-navbar> </uv-navbar>
</uv-sticky> </uv-sticky> -->
<uv-list> <uv-list>
<uv-list-item <uv-list-item
@@ -24,12 +24,20 @@
clickable clickable
show-arrow show-arrow
:title="item.id" :title="item.id"
:note="item.id"
:right-text="item.id" :right-text="item.projectType"
@click="toDetails(item)" @click="toDetails(item)"
></uv-list-item> ></uv-list-item>
</uv-list> </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_project: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-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-empty v-if="pager.loading =='nomore'&&pager.lists.length == 0" marginTop="150" mode="data"></uv-empty>
@@ -71,6 +79,8 @@
updateTimeStart: '', updateTimeStart: '',
updateTimeEnd: '', updateTimeEnd: '',
}); });
let activeFab = ref(false);
let fromSearch=ref(false); let fromSearch=ref(false);
onLoad((e) => { onLoad((e) => {
console.log("monitor_project onLoad", e); console.log("monitor_project onLoad", e);
@@ -105,9 +115,21 @@
function moreSearch() { function moreSearch() {
toPath("/pages/monitor_project/search"); toPath("/pages/monitor_project/search");
} }
function add() {
toPath("/pages/monitor_project/edit");
}
</script> </script>
<style lang="scss" scoped> <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> </style>

View File

@@ -8,12 +8,12 @@
<uv-input v-model="form.projectName"> </uv-input> <uv-input v-model="form.projectName"> </uv-input>
</uv-form-item> </uv-form-item>
<uv-form-item label="项目类型" prop="projectType" borderBottom> <uv-form-item label="项目类型" prop="projectType" borderBottom>
<!-- <x-picker <x-picker
v-model="form.projectType" v-model="form.projectType"
valueKey="value" valueKey="value"
labelKey="name" labelKey="name"
:columns="dictData.project_type" :columns="dictData.project_type"
></x-picker> --> ></x-picker>
</uv-form-item> </uv-form-item>
<uv-form-item label="创建时间" prop="createTime" borderBottom> <uv-form-item label="创建时间" prop="createTime" borderBottom>
<xDateRange <xDateRange

View File

@@ -10,8 +10,8 @@ export const useUserStore = defineStore("user", {
username: "", username: "",
avatar: "", avatar: "",
userInfo: {}, userInfo: {},
menu: [], // menu: [],
auth: [], permissions: [],
}; };
}, },
// 也可以这样定义 // 也可以这样定义
@@ -33,7 +33,7 @@ export const useUserStore = defineStore("user", {
this.avatar = data.user.avatar ||""; this.avatar = data.user.avatar ||"";
// this.menu = data.menu; // this.menu = data.menu;
// this.auth = data.auth; this.permissions = data.permissions;
this.userInfo = data.user; this.userInfo = data.user;
resolve(data); resolve(data);
} else { } else {

View File

@@ -1,12 +1,12 @@
import { useUserStore } from "@/stores/user"; import { useUserStore } from "@/stores/user";
export const perms = (perms:string) => { export const perms = (perms:string) => {
if (!perms) return true; if (!perms) return false;
const userStore = useUserStore(); const userStore = useUserStore();
const auth = userStore.auth; const permissions = userStore.permissions;
let find = auth.find((item) => { let find = permissions.find((item) => {
return item.action === perms; return item === perms|| item === "*";
}); });
return !!find; return !!find;
}; };