1
0

feat(web): 使用vite重新组织前端代码

This commit is contained in:
2024-11-19 17:52:34 +08:00
parent 7ccc602406
commit 9a01d74d78
138 changed files with 1141 additions and 443 deletions

View File

@@ -0,0 +1,137 @@
const information = {
debug: false,
// baseUrl: '',
baseUrl: 'http://127.0.0.1:20080',
title: '可信供给中心',
}
export function useAmis(amisObject) {
document.title = information.title
let amis = amisRequire('amis/embed')
amis.embed(
'#app',
amisObject(information),
{
data: {
base: information.baseUrl,
},
},
{
theme: 'antd',
enableAMISDebug: information.debug,
}
)
}
export function crudCommonOptions() {
return {
affixHeader: false,
stopAutoRefreshWhenModalIsOpen: true,
resizable: false,
syncLocation: false,
silentPolling: true,
}
}
export function readOnlyDialogOptions() {
return {
actions: [],
showCloseButton: false,
closeOnEsc: true,
closeOnOutside: true,
disabled: true,
}
}
export function horizontalFormOptions() {
return {
mode: 'horizontal',
canAccessSuperData: false,
horizontal: {
left: 2,
},
}
}
export function paginationCommonOptions(perPage = true, maxButtons = 5) {
let option = {
type: 'pagination',
layout: [
'pager'
],
maxButtons: maxButtons,
showPageInput: false,
perPageAvailable: [10, 15, 20, 50, 100, 200],
}
if (perPage) {
option.layout.push('perPage')
}
return option
}
export function paginationTemplate(perPage = 20, maxButtons = 5) {
return {
perPage: perPage,
headerToolbar: [
"reload",
paginationCommonOptions(true, maxButtons),
],
footerToolbar: [
"statistics",
paginationCommonOptions(true, maxButtons),
],
}
}
export function mappingField(field, mapping) {
let mapData = {
'*': `<span class='label bg-gray-300'>\${${field}}</span>`,
}
mapping.forEach(item => {
mapData[item['value']] = `<span class='label ${item['color']}'>${item['label']}</span>`
})
return {
type: 'mapping',
value: `\${${field}}`,
map: mapData,
}
}
function mappingItem(label, value, color = 'bg-info') {
return {
label: label,
value: value,
color: color,
}
}
export const userRoleMapping = [
mappingItem('数据提供方', 'PROVIDER', 'bg-blue-500'),
mappingItem('数据使用方', 'CUSTOMER', 'bg-purple-500'),
mappingItem('审核监管方', 'CHECKER', 'bg-cyan-500'),
mappingItem('系统管理员', 'ADMINISTRATOR', 'bg-green-500'),
]
export const userStateMapping = [
mappingItem('审查中', 'CHECKING', 'bg-warning'),
mappingItem('正常', 'NORMAL', 'bg-success'),
mappingItem('禁用', 'DISABLED', 'bg-danger'),
]
function api(method, url) {
return {
method: method,
url: url,
headers: {
token: '${token|default:undefined}',
}
}
}
export function apiGet(url) {
return api('get', url)
}
export function apiPost(url) {
return api('post', url)
}

View File

@@ -0,0 +1,38 @@
import {horizontalFormOptions, apiPost} from '../constants.js'
import {confirmPasswordFormItem, passwordFormItem} from "./dialog-user-item.js";
export function userChangePasswordDialog() {
return {
actionType: 'dialog',
dialog: {
title: '修改密码',
actions: [
{
type: 'reset',
label: '清空',
},
{
type: 'submit',
label: '修改',
level: 'primary',
}
],
body: {
type: 'form',
api: apiPost('${base}/user_management/change_password'),
...horizontalFormOptions(),
body: [
{
type: 'input-password',
name: 'oldPassword',
label: '旧密码',
placeholder: '请输入旧密码',
required: true,
},
passwordFormItem('newPassword', '新密码'),
confirmPasswordFormItem('confirmNewPassword', 'newPassword', '新密码'),
]
}
}
}
}

View File

@@ -0,0 +1,61 @@
import {apiGet, horizontalFormOptions, mappingField, userRoleMapping, userStateMapping} from "../constants.js";
export function userCheckDialog() {
return {
actionType: 'dialog',
dialog: {
title: '用户注册',
actions: [
{
type: 'action',
label: '同意',
level: 'primary',
actionType: 'ajax',
api: apiGet('${base}/user_management/enable/${username}'),
confirmTitle: '审核通过',
confirmText: '确认通过账号为${username}通过审核吗?审核通过后将无法撤销。',
reload: '9200849e-a8e9-4752-b4fc-ae52dc46a205',
},
],
body: {
type: 'form',
initApi: apiGet('${base}/user_management/detail/${username}'),
...horizontalFormOptions(),
static: true,
body: [
{
type: 'input-email',
name: 'username',
label: '邮箱',
},
{
type: 'control',
name: 'role',
label: '角色',
body: [
mappingField('role', userRoleMapping),
]
},
{
type: 'control',
name: 'state',
label: '账号状态',
body: [
mappingField('state', userStateMapping)
]
},
{
type: 'input-datetime',
name: 'createTime',
label: '创建时间',
},
{
type: 'input-datetime',
name: 'updateTime',
label: '更新时间',
},
]
}
}
}
}

View File

@@ -0,0 +1,49 @@
export function emailFormItem(name) {
return {
type: 'input-email',
name: name,
label: '邮箱',
placeholder: '请输入邮箱',
required: true,
clearable: true,
clearValueOnEmpty: true,
validateApi: '${base}/user/exists_username/${username}',
}
}
export function passwordFormItem(name, label = '密码') {
return {
type: 'input-password',
name: name,
label: label,
placeholder: `请输入${label}`,
required: true,
clearable: true,
clearValueOnEmpty: true,
validations: {
matchRegexp:
/^(?=.*\d)(?!.*(\d)\1{2})(?!.*(012|123|234|345|456|567|678|789|987|876|765|654|543|432|321|210))(?=.*[a-zA-Z])(?=.*[^\da-zA-Z\s]).{8,16}$/,
},
validationErrors: {
matchRegexp:
`${label}至少包含字母、数字、特殊字符8-16位并且不能连续出现3个大小连续或相同的数字`,
},
}
}
export function confirmPasswordFormItem(name, target, label = '密码') {
return {
type: 'input-password',
name: name,
label: `确认${label}`,
placeholder: `请再次输入${label}`,
required: true,
clearable: true,
validations: {
equalsField: target,
},
validationErrors: {
equalsField: `两次输入${label}不一致`,
},
}
}

View File

@@ -0,0 +1,89 @@
import {apiPost, horizontalFormOptions} from '../constants.js'
import {confirmPasswordFormItem, emailFormItem, passwordFormItem} from "./dialog-user-item.js";
export function userRegisterDialog() {
return {
actionType: 'dialog',
dialog: {
title: '用户注册',
actions: [
{
type: 'reset',
label: '清空',
},
{
type: 'submit',
label: '注册',
level: 'primary',
},
],
body: {
type: 'form',
api: apiPost('${base}/user/register'),
...horizontalFormOptions(),
body: [
emailFormItem('username'),
passwordFormItem('password'),
confirmPasswordFormItem('confirm-password', 'password'),
{
type: 'radios',
name: 'role',
label: '角色',
required: true,
selectFirst: true,
options: [
{ label: '数据提供方', value: 'PROVIDER' },
{ label: '数据使用方', value: 'CUSTOMER' },
{ label: '审查监管方', value: 'CHECKER' },
],
},
],
},
},
}
}
export function userAdministratorRegisterDialog() {
return {
actionType: 'dialog',
dialog: {
title: '用户注册',
actions: [
{
type: 'reset',
label: '清空',
},
{
type: 'submit',
label: '注册',
level: 'primary',
},
],
body: {
type: 'form',
api: apiPost('${base}/user_management/register'),
...horizontalFormOptions(),
body: [
emailFormItem('username'),
passwordFormItem('password'),
confirmPasswordFormItem('confirm-password', 'password'),
{
type: 'radios',
name: 'role',
label: '角色',
required: true,
selectFirst: true,
inline: false,
columnsCount: 2,
options: [
{ label: '数据提供方', value: 'PROVIDER' },
{ label: '数据使用方', value: 'CUSTOMER' },
{ label: '审查监管方', value: 'CHECKER' },
{ label: '系统管理员', value: 'ADMINISTRATOR' },
],
},
],
},
},
}
}