Skip to content

Commit 7d82785

Browse files
author
piexlmax
committed
修复pgsql从数据库表获取key的问题
1 parent 4e8544c commit 7d82785

File tree

2 files changed

+59
-43
lines changed

2 files changed

+59
-43
lines changed

server/service/system/sys_auto_code_pgsql.go

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,52 @@ func (a *autoCodePgsql) GetTables(dbName string) (data []response.Table, err err
4343
func (a *autoCodePgsql) GetColumn(tableName string, dbName string) (data []response.Column, err error) {
4444
// todo 数据获取不全, 待完善sql
4545
sql := `
46-
SELECT columns.COLUMN_NAME as column_name,
47-
columns.DATA_TYPE as data_type,
48-
CASE
49-
columns.DATA_TYPE
50-
WHEN 'text' THEN
51-
concat_ws('', '', columns.CHARACTER_MAXIMUM_LENGTH)
52-
WHEN 'varchar' THEN
53-
concat_ws('', '', columns.CHARACTER_MAXIMUM_LENGTH)
54-
WHEN 'smallint' THEN
55-
concat_ws(',', columns.NUMERIC_PRECISION, columns.NUMERIC_SCALE)
56-
WHEN 'decimal' THEN
57-
concat_ws(',', columns.NUMERIC_PRECISION, columns.NUMERIC_SCALE)
58-
WHEN 'integer' THEN
59-
concat_ws('', '', columns.NUMERIC_PRECISION)
60-
WHEN 'bigint' THEN
61-
concat_ws('', '', columns.NUMERIC_PRECISION)
62-
ELSE ''
63-
END AS data_type_long,
64-
(select description.description
65-
from pg_description description
66-
where description.objoid = (select attribute.attrelid
67-
from pg_attribute attribute
68-
where attribute.attrelid =
69-
(select oid from pg_class class where class.relname = '@table_name') and attname =columns.COLUMN_NAME )
70-
and description.objsubid = (select attribute.attnum
71-
from pg_attribute attribute
72-
where attribute.attrelid =
73-
(select oid from pg_class class where class.relname = '@table_name') and attname =columns.COLUMN_NAME )) as column_comment
74-
FROM INFORMATION_SCHEMA.COLUMNS columns
75-
WHERE table_catalog = '?'
76-
and table_schema = 'public'
77-
and table_name = '?';
46+
SELECT psc.COLUMN_NAME AS COLUMN_NAME,
47+
psc.udt_name AS data_type,
48+
CASE
49+
psc.udt_name
50+
WHEN 'text' THEN
51+
concat_ws ( '', '', psc.CHARACTER_MAXIMUM_LENGTH )
52+
WHEN 'varchar' THEN
53+
concat_ws ( '', '', psc.CHARACTER_MAXIMUM_LENGTH )
54+
WHEN 'smallint' THEN
55+
concat_ws ( ',', psc.NUMERIC_PRECISION, psc.NUMERIC_SCALE )
56+
WHEN 'decimal' THEN
57+
concat_ws ( ',', psc.NUMERIC_PRECISION, psc.NUMERIC_SCALE )
58+
WHEN 'integer' THEN
59+
concat_ws ( '', '', psc.NUMERIC_PRECISION )
60+
WHEN 'int4' THEN
61+
concat_ws ( '', '', psc.NUMERIC_PRECISION )
62+
WHEN 'int8' THEN
63+
concat_ws ( '', '', psc.NUMERIC_PRECISION )
64+
WHEN 'bigint' THEN
65+
concat_ws ( '', '', psc.NUMERIC_PRECISION )
66+
WHEN 'timestamp' THEN
67+
concat_ws ( '', '', psc.datetime_precision )
68+
ELSE ''
69+
END AS data_type_long,
70+
(
71+
SELECT
72+
pd.description
73+
FROM
74+
pg_description pd
75+
WHERE
76+
(pd.objoid,pd.objsubid) in (
77+
SELECT pa.attrelid,pa.attnum
78+
FROM
79+
pg_attribute pa
80+
WHERE pa.attrelid = ( SELECT oid FROM pg_class pc WHERE
81+
pc.relname = psc.table_name
82+
)
83+
and attname = psc.column_name
84+
)
85+
) AS column_comment
86+
FROM
87+
INFORMATION_SCHEMA.COLUMNS psc
88+
WHERE
89+
table_catalog = ?
90+
AND table_schema = 'public'
91+
AND TABLE_NAME = ?;
7892
`
7993
var entities []response.Column
8094
db, _err := gorm.Open(postgres.Open(global.GVA_CONFIG.Pgsql.LinkDsn(dbName)), &gorm.Config{Logger: logger.Default.LogMode(logger.Info)})

web/src/permission.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ const getRouter = async(userStore) => {
1818
}
1919

2020
async function handleKeepAlive(to) {
21-
if (to.matched && to.matched.length > 2) {
22-
for (let i = 1; i < to.matched.length; i++) {
23-
const element = to.matched[i - 1]
24-
if (element.name === 'layout') {
25-
to.matched.splice(i, 1)
26-
await handleKeepAlive(to)
27-
}
28-
// 如果没有按需加载完成则等待加载
29-
if (typeof element.components.default === 'function') {
30-
await element.components.default()
31-
await handleKeepAlive(to)
21+
if (to.matched.some(item => item.meta.keepAlive)) {
22+
if (to.matched && to.matched.length > 2) {
23+
for (let i = 1; i < to.matched.length; i++) {
24+
const element = to.matched[i - 1]
25+
if (element.name === 'layout') {
26+
to.matched.splice(i, 1)
27+
await handleKeepAlive(to)
28+
}
29+
// 如果没有按需加载完成则等待加载
30+
if (typeof element.components.default === 'function') {
31+
await element.components.default()
32+
await handleKeepAlive(to)
33+
}
3234
}
3335
}
3436
}

0 commit comments

Comments
 (0)