feat: suffix naming rules, extension consistency, column widths, compact layout
- suffix rows are named by the suffix at creation (prompt); names are immutable afterwards; duplicates auto-suffix -1/-2 (global) - new-group dialog takes group name + first suffix name; backend creates group and its first workspace row in one transaction - upload validation: file extension must match the row's suffix (whole-row consistency), enforced client- and server-side - column sort dialog gains per-column width inputs (persisted via PATCH /columns/:id, table renders fixed widths, 0 = auto) - compact layout: denser tables/bars, viewport-height shell with independent scrollbars, cleanup step in e2e flow
This commit is contained in:
@@ -39,6 +39,7 @@ func registerSuffixRoutes(secured *gin.RouterGroup, a *BusinessAPI) {
|
||||
s.POST("/dirs/:id/columns", a.createSuffixColumn)
|
||||
s.POST("/dirs/:id/columns/order", a.reorderSuffixColumns)
|
||||
s.POST("/dirs/:id/anchor", a.setSuffixAnchor)
|
||||
s.PATCH("/columns/:id", a.updateSuffixColumn)
|
||||
s.DELETE("/columns/:id", a.deleteSuffixColumn)
|
||||
s.PUT("/cells", a.saveSuffixCell)
|
||||
s.GET("/overview", a.suffixOverview)
|
||||
@@ -221,6 +222,7 @@ type suffixColumnRow struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
IsValue bool `json:"is_value"`
|
||||
Width int `json:"width"`
|
||||
}
|
||||
|
||||
func (a *BusinessAPI) suffixDirPage(c *gin.Context) {
|
||||
@@ -231,14 +233,14 @@ func (a *BusinessAPI) suffixDirPage(c *gin.Context) {
|
||||
}
|
||||
columns := []suffixColumnRow{}
|
||||
colRows, err := a.db.QueryContext(c,
|
||||
"SELECT id,name,is_value FROM suffix_columns WHERE dir_id=? ORDER BY sort_order ASC,id ASC", dirID)
|
||||
"SELECT id,name,is_value,width FROM suffix_columns WHERE dir_id=? ORDER BY sort_order ASC,id ASC", dirID)
|
||||
if err != nil {
|
||||
apiError(c, 500, "internal_error", "列加载失败")
|
||||
return
|
||||
}
|
||||
for colRows.Next() {
|
||||
var col suffixColumnRow
|
||||
if err := colRows.Scan(&col.ID, &col.Name, &col.IsValue); err != nil {
|
||||
if err := colRows.Scan(&col.ID, &col.Name, &col.IsValue, &col.Width); err != nil {
|
||||
colRows.Close()
|
||||
apiError(c, 500, "internal_error", "列加载失败")
|
||||
return
|
||||
@@ -306,6 +308,7 @@ func (a *BusinessAPI) createSuffixColumn(c *gin.Context) {
|
||||
var in struct {
|
||||
Name string `json:"name"`
|
||||
IsValue bool `json:"is_value"`
|
||||
Width int `json:"width"`
|
||||
AfterID uint64 `json:"after_id"`
|
||||
}
|
||||
if c.ShouldBindJSON(&in) != nil {
|
||||
@@ -317,6 +320,10 @@ func (a *BusinessAPI) createSuffixColumn(c *gin.Context) {
|
||||
apiError(c, 400, "invalid_request", "列名须为 1–190 字")
|
||||
return
|
||||
}
|
||||
if in.Width < 0 || in.Width > 2000 {
|
||||
apiError(c, 400, "invalid_request", "列宽须为 0–2000(0=自适应)")
|
||||
return
|
||||
}
|
||||
var dup int
|
||||
if a.db.QueryRowContext(c,
|
||||
"SELECT 1 FROM suffix_columns WHERE dir_id=? AND name=?", dirID, name).Scan(&dup) == nil {
|
||||
@@ -346,14 +353,14 @@ func (a *BusinessAPI) createSuffixColumn(c *gin.Context) {
|
||||
sortAt = int(order.Int64)
|
||||
}
|
||||
res, err := a.db.ExecContext(c,
|
||||
"INSERT INTO suffix_columns(dir_id,name,is_value,sort_order) VALUES(?,?,?,?)",
|
||||
dirID, name, in.IsValue, sortAt+1)
|
||||
"INSERT INTO suffix_columns(dir_id,name,is_value,sort_order,width) VALUES(?,?,?,?,?)",
|
||||
dirID, name, in.IsValue, sortAt+1, in.Width)
|
||||
if err != nil {
|
||||
apiError(c, 500, "internal_error", "列创建失败")
|
||||
return
|
||||
}
|
||||
id, _ := res.LastInsertId()
|
||||
c.JSON(201, gin.H{"data": gin.H{"id": id, "name": name, "is_value": in.IsValue}})
|
||||
c.JSON(201, gin.H{"data": gin.H{"id": id, "name": name, "is_value": in.IsValue, "width": in.Width}})
|
||||
}
|
||||
|
||||
func (a *BusinessAPI) reorderSuffixColumns(c *gin.Context) {
|
||||
@@ -415,6 +422,28 @@ func (a *BusinessAPI) reorderSuffixColumns(c *gin.Context) {
|
||||
c.JSON(200, gin.H{"data": gin.H{"ok": true, "ordered": len(final)}})
|
||||
}
|
||||
|
||||
func (a *BusinessAPI) updateSuffixColumn(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
var in struct {
|
||||
Width *int `json:"width"`
|
||||
}
|
||||
if c.ShouldBindJSON(&in) != nil || in.Width == nil {
|
||||
apiError(c, 400, "invalid_request", "width 必填")
|
||||
return
|
||||
}
|
||||
w := *in.Width
|
||||
if w < 0 || w > 2000 {
|
||||
apiError(c, 400, "invalid_request", "列宽须为 0–2000(0=自适应)")
|
||||
return
|
||||
}
|
||||
res, err := a.db.ExecContext(c, "UPDATE suffix_columns SET width=? WHERE id=?", w, id)
|
||||
if err != nil || rowsAffected(res) == 0 {
|
||||
apiError(c, 404, "not_found", "列不存在")
|
||||
return
|
||||
}
|
||||
c.JSON(200, gin.H{"data": gin.H{"id": id, "width": w}})
|
||||
}
|
||||
|
||||
func (a *BusinessAPI) deleteSuffixColumn(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
res, err := a.db.ExecContext(c, "DELETE FROM suffix_columns WHERE id=?", id)
|
||||
@@ -591,6 +620,7 @@ type suffixOverview struct {
|
||||
func (a *BusinessAPI) createSuffixGroup(c *gin.Context) {
|
||||
var in struct {
|
||||
Name string `json:"name"`
|
||||
FirstSuffixName string `json:"first_suffix_name"`
|
||||
}
|
||||
if c.ShouldBindJSON(&in) != nil {
|
||||
apiError(c, 400, "invalid_request", "参数无效")
|
||||
@@ -606,6 +636,19 @@ func (a *BusinessAPI) createSuffixGroup(c *gin.Context) {
|
||||
apiError(c, 409, "duplicate_name", "已有同名分组")
|
||||
return
|
||||
}
|
||||
// 首个后缀名可选:填了就随组自动建一行工作行(同名自动 -1)。
|
||||
firstName, firstOK := suffixTrimName(in.FirstSuffixName, 64)
|
||||
if firstOK {
|
||||
final := firstName
|
||||
for i := 1; ; i++ {
|
||||
var dup2 int
|
||||
if a.db.QueryRowContext(c, "SELECT 1 FROM suffixes WHERE name=?", final).Scan(&dup2) != nil {
|
||||
break
|
||||
}
|
||||
final = firstName + "-" + strconv.Itoa(i)
|
||||
}
|
||||
firstName = final
|
||||
}
|
||||
var order sql.NullInt64
|
||||
_ = a.db.QueryRowContext(c, "SELECT MAX(sort_order) FROM suffix_groups").Scan(&order)
|
||||
tx, err := a.db.BeginTx(c, nil)
|
||||
@@ -621,17 +664,22 @@ func (a *BusinessAPI) createSuffixGroup(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
gid, _ := gres.LastInsertId()
|
||||
// 新建分组自动带一行工作行,按钮齐全,双击即可命名。
|
||||
if _, err := tx.ExecContext(c,
|
||||
"INSERT INTO suffixes(group_id,name,sort_order) VALUES(?,'',0)", gid); err != nil {
|
||||
created := []suffixOverview{}
|
||||
if firstOK {
|
||||
sres, err := tx.ExecContext(c,
|
||||
"INSERT INTO suffixes(group_id,name,sort_order) VALUES(?,?,0)", gid, firstName)
|
||||
if err != nil {
|
||||
apiError(c, 500, "internal_error", "分组创建失败")
|
||||
return
|
||||
}
|
||||
sid, _ := sres.LastInsertId()
|
||||
created = append(created, suffixOverview{ID: uint64(sid), Name: firstName})
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
apiError(c, 500, "internal_error", "分组创建失败")
|
||||
return
|
||||
}
|
||||
c.JSON(201, gin.H{"data": gin.H{"id": gid, "name": name, "suffixes": []suffixOverview{}}})
|
||||
c.JSON(201, gin.H{"data": gin.H{"id": gid, "name": name, "suffixes": created}})
|
||||
}
|
||||
|
||||
func (a *BusinessAPI) renameSuffixGroup(c *gin.Context) {
|
||||
@@ -715,12 +763,28 @@ func (a *BusinessAPI) suffixFilesOnDisk(c *gin.Context, groupID uint64) []string
|
||||
func (a *BusinessAPI) createSuffix(c *gin.Context) {
|
||||
var in struct {
|
||||
GroupID uint64 `json:"group_id"`
|
||||
Name string `json:"name"`
|
||||
AfterID uint64 `json:"after_id"`
|
||||
}
|
||||
if c.ShouldBindJSON(&in) != nil || in.GroupID == 0 {
|
||||
apiError(c, 400, "invalid_request", "参数无效")
|
||||
return
|
||||
}
|
||||
name, ok := suffixTrimName(in.Name, 64)
|
||||
if !ok {
|
||||
apiError(c, 400, "invalid_request", "后缀名须为 1–64 字")
|
||||
return
|
||||
}
|
||||
// 名称按后缀命名且不可修改:全局查重,同名自动 -1、-2…
|
||||
final := name
|
||||
for i := 1; ; i++ {
|
||||
var dup int
|
||||
if a.db.QueryRowContext(c, "SELECT 1 FROM suffixes WHERE name=?", final).Scan(&dup) != nil {
|
||||
break
|
||||
}
|
||||
final = name + "-" + strconv.Itoa(i)
|
||||
}
|
||||
name = final
|
||||
var groupSort int
|
||||
if err := a.db.QueryRowContext(c,
|
||||
"SELECT sort_order FROM suffix_groups WHERE id=?", in.GroupID).Scan(&groupSort); err != nil {
|
||||
@@ -756,7 +820,7 @@ func (a *BusinessAPI) createSuffix(c *gin.Context) {
|
||||
}
|
||||
res, err := tx.ExecContext(c,
|
||||
"INSERT INTO suffixes(group_id,name,sort_order) VALUES(?,?,?)",
|
||||
in.GroupID, "", sortAfter+1)
|
||||
in.GroupID, name, sortAfter+1)
|
||||
if err != nil {
|
||||
apiError(c, 500, "internal_error", "后缀创建失败")
|
||||
return
|
||||
@@ -766,7 +830,7 @@ func (a *BusinessAPI) createSuffix(c *gin.Context) {
|
||||
apiError(c, 500, "internal_error", "后缀创建失败")
|
||||
return
|
||||
}
|
||||
c.JSON(201, gin.H{"data": gin.H{"id": id, "group_id": in.GroupID, "name": ""}})
|
||||
c.JSON(201, gin.H{"data": gin.H{"id": id, "group_id": in.GroupID, "name": name}})
|
||||
}
|
||||
|
||||
func (a *BusinessAPI) renameSuffix(c *gin.Context) {
|
||||
@@ -894,6 +958,25 @@ func (a *BusinessAPI) uploadSuffixFile(c *gin.Context) {
|
||||
apiError(c, 400, "invalid_request", "文件哈希校验失败,请重新上传")
|
||||
return
|
||||
}
|
||||
// 扩展名必须与本行后缀一致(整行统一):行名去掉 -N 去重尾缀后即为预期扩展名。
|
||||
var suffixName string
|
||||
if err := a.db.QueryRowContext(c,
|
||||
"SELECT name FROM suffixes WHERE id=?", suffixID).Scan(&suffixName); err != nil {
|
||||
apiError(c, 404, "not_found", "后缀不存在")
|
||||
return
|
||||
}
|
||||
base := suffixName
|
||||
if i := strings.LastIndex(base, "-"); i > 0 {
|
||||
if _, err := strconv.Atoi(base[i+1:]); err == nil {
|
||||
base = base[:i]
|
||||
}
|
||||
}
|
||||
fileExt := strings.ToLower(strings.TrimPrefix(filepath.Ext(fileName), "."))
|
||||
if fileExt == "" || fileExt != strings.ToLower(base) {
|
||||
apiError(c, 400, "extension_mismatch",
|
||||
fmt.Sprintf("上传文件的扩展名必须与本行后缀一致:本行是「%s」,只能上传 .%s 文件", suffixName, strings.ToLower(base)))
|
||||
return
|
||||
}
|
||||
root, rootErr := suffixTemplateRoot()
|
||||
if rootErr != nil {
|
||||
apiError(c, 500, "storage_unconfigured", "PACKAGE_STORAGE_ROOT 未配置,模板无法落盘")
|
||||
|
||||
@@ -115,14 +115,34 @@ func TestSuffixAdminIntegration(t *testing.T) {
|
||||
if w.Code != 409 {
|
||||
t.Fatalf("重名分组 status=%d, want 409", w.Code)
|
||||
}
|
||||
w = authed(http.MethodPost, "/api/v1/suffix-admin/suffixes", fmt.Sprintf(`{"group_id":%d}`, groupID))
|
||||
w = authed(http.MethodPost, "/api/v1/suffix-admin/suffixes", fmt.Sprintf(`{"group_id":%d,"name":"cos4"}`, groupID))
|
||||
if w.Code != 201 {
|
||||
t.Fatalf("建后缀 status=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
suffixID := uint64(getJSON(w)["data"].(map[string]any)["id"].(float64))
|
||||
w = authed(http.MethodPut, fmt.Sprintf("/api/v1/suffix-admin/suffixes/%d", suffixID), `{"name":"cos4"}`)
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("改后缀名 status=%d body=%s", w.Code, w.Body.String())
|
||||
// 建组带首个后缀名 → 自动工作行
|
||||
w = authed(http.MethodPost, "/api/v1/suffix-admin/groups", `{"name":"广西自治区","first_suffix_name":"xml"}`)
|
||||
if w.Code != 201 {
|
||||
t.Fatalf("建组带后缀 status=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
gx := uint64(getJSON(w)["data"].(map[string]any)["id"].(float64))
|
||||
sx := getJSON(w)["data"].(map[string]any)["suffixes"].([]any)
|
||||
if len(sx) != 1 || sx[0].(map[string]any)["name"] != "xml" {
|
||||
t.Fatalf("首后缀自动行不符: %v", sx)
|
||||
}
|
||||
_ = gx
|
||||
// 同名再建 → 自动 -1
|
||||
w = authed(http.MethodPost, "/api/v1/suffix-admin/suffixes", fmt.Sprintf(`{"group_id":%d,"name":"cos4"}`, groupID))
|
||||
if w.Code != 201 {
|
||||
t.Fatalf("同名后缀 status=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
if got := getJSON(w)["data"].(map[string]any)["name"]; got != "cos4-1" {
|
||||
t.Fatalf("同名自动 -1: got %v", got)
|
||||
}
|
||||
// 空名 → 400
|
||||
w = authed(http.MethodPost, "/api/v1/suffix-admin/suffixes", fmt.Sprintf(`{"group_id":%d,"name":""}`, groupID))
|
||||
if w.Code != 400 {
|
||||
t.Fatalf("空名 status=%d, want 400", w.Code)
|
||||
}
|
||||
|
||||
// 目录树:根 + 子目录 + 改名 + 删除保护
|
||||
@@ -240,6 +260,13 @@ func TestSuffixAdminIntegration(t *testing.T) {
|
||||
content := []byte("COS4-skeleton-demo")
|
||||
sum := sha256.Sum256(content)
|
||||
b64 := base64.StdEncoding.EncodeToString(content)
|
||||
// 扩展名与本行后缀不符 → 400
|
||||
w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/suffixes/%d/files", suffixID),
|
||||
fmt.Sprintf(`{"file_name":"骨架.xml","size":%d,"sha256":"%s","content_base64":"%s"}`,
|
||||
len(content), hex.EncodeToString(sum[:]), b64))
|
||||
if w.Code != 400 {
|
||||
t.Fatalf("扩展名不符 status=%d, want 400", w.Code)
|
||||
}
|
||||
w = authed(http.MethodPost, fmt.Sprintf("/api/v1/suffix-admin/suffixes/%d/files", suffixID),
|
||||
fmt.Sprintf(`{"file_name":"骨架.cos4","size":%d,"sha256":"%s","content_base64":"%s"}`,
|
||||
len(content), hex.EncodeToString(sum[:]), b64))
|
||||
|
||||
@@ -32,6 +32,7 @@ CREATE TABLE suffix_columns (
|
||||
name VARCHAR(190) NOT NULL,
|
||||
is_value BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
width INT NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
CONSTRAINT fk_suffix_columns_dir FOREIGN KEY(dir_id) REFERENCES suffix_dirs(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { api } from './api'
|
||||
// 后缀管理(业务管理 → 后缀管理):目录树 / 分组 / 后缀 / 列 / 单元格 / 模板文件。
|
||||
|
||||
export type SuffixDir = { id:number; parent_id:number; name:string; sort_order:number; children:number }
|
||||
export type SuffixColumn = { id:number; name:string; is_value:boolean }
|
||||
export type SuffixColumn = { id:number; name:string; is_value:boolean; width:number }
|
||||
export type SuffixLine = { id:number; group_id:number; group_name:string; name:string; anchor:boolean }
|
||||
export type SuffixPage = { dir_id:number; columns:SuffixColumn[]; suffixes:SuffixLine[]; cells:Record<string,string> }
|
||||
export type SuffixFile = { id:number; suffix_id?:number; file_name:string; file_size:number; created_at?:string; sha256?:string }
|
||||
@@ -15,17 +15,18 @@ export const renameSuffixDir = (id:number, name:string) => api.put<{data:SuffixD
|
||||
export const moveSuffixDir = (id:number, dir:number) => api.post(`/suffix-admin/dirs/${id}/move`, { dir })
|
||||
export const deleteSuffixDir = (id:number) => api.delete(`/suffix-admin/dirs/${id}`)
|
||||
export const getSuffixPage = (id:number) => api.get<{data:SuffixPage}>(`/suffix-admin/dirs/${id}/page`)
|
||||
export const createSuffixColumn = (dirId:number, name:string, is_value:boolean, after_id = 0) => api.post<{data:SuffixColumn}>(`/suffix-admin/dirs/${dirId}/columns`, { name, is_value, after_id })
|
||||
export const createSuffixColumn = (dirId:number, name:string, is_value:boolean, after_id = 0, width = 0) => api.post<{data:SuffixColumn}>(`/suffix-admin/dirs/${dirId}/columns`, { name, is_value, after_id, width })
|
||||
export const updateSuffixColumnWidth = (id:number, width:number) => api.patch<{data:{id:number;width:number}}>(`/suffix-admin/columns/${id}`, { width })
|
||||
export const reorderSuffixColumns = (dirId:number, ids:number[]) => api.post<{data:{ok:boolean;ordered:number}}>(`/suffix-admin/dirs/${dirId}/columns/order`, { ids })
|
||||
export const deleteSuffixColumn = (id:number) => api.delete(`/suffix-admin/columns/${id}`)
|
||||
export const saveSuffixCell = (dir_id:number, suffix_id:number, column_id:number, value:string) => api.put('/suffix-admin/cells', { dir_id, suffix_id, column_id, value })
|
||||
export const setSuffixAnchor = (dirId:number, suffix_id:number, on:boolean) => api.post(`/suffix-admin/dirs/${dirId}/anchor`, { suffix_id, on })
|
||||
export const getSuffixOverview = () => api.get<{data:{groups:SuffixGroup[]}}>('/suffix-admin/overview')
|
||||
export const createSuffixGroup = (name:string) => api.post<{data:SuffixGroup}>('/suffix-admin/groups', { name })
|
||||
export const createSuffixGroup = (name:string, first_suffix_name = '') => api.post<{data:SuffixGroup}>('/suffix-admin/groups', { name, first_suffix_name })
|
||||
export const renameSuffixGroup = (id:number, name:string) => api.put(`/suffix-admin/groups/${id}`, { name })
|
||||
export const moveSuffixGroup = (id:number, dir:number) => api.post(`/suffix-admin/groups/${id}/move`, { dir })
|
||||
export const deleteSuffixGroup = (id:number) => api.delete(`/suffix-admin/groups/${id}`)
|
||||
export const createSuffix = (group_id:number, after_id = 0) => api.post<{data:{id:number;group_id:number;name:string}}>('/suffix-admin/suffixes', { group_id, after_id })
|
||||
export const createSuffix = (group_id:number, name:string, after_id = 0) => api.post<{data:{id:number;group_id:number;name:string}}>('/suffix-admin/suffixes', { group_id, name, after_id })
|
||||
export const renameSuffix = (id:number, name:string) => api.put(`/suffix-admin/suffixes/${id}`, { name })
|
||||
export const moveSuffix = (id:number, dir:number) => api.post(`/suffix-admin/suffixes/${id}/move`, { dir })
|
||||
export const deleteSuffix = (id:number) => api.delete(`/suffix-admin/suffixes/${id}`)
|
||||
|
||||
@@ -2,7 +2,7 @@ import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import SuffixPanel from './SuffixPanel.vue'
|
||||
import {
|
||||
createSuffixColumn, getSuffixOverview, getSuffixPage, getSuffixTree,
|
||||
createSuffixColumn, getSuffixOverview, getSuffixPage, getSuffixTree, updateSuffixColumnWidth,
|
||||
} from '../suffix-admin'
|
||||
|
||||
vi.mock('../suffix-admin', () => ({
|
||||
@@ -14,6 +14,7 @@ vi.mock('../suffix-admin', () => ({
|
||||
formatSuffixSize: (n: number) => n + ' B',
|
||||
suffixFileUrl: (id: number) => `/api/v1/suffix-admin/files/${id}/download`,
|
||||
getSuffixTree: vi.fn(),
|
||||
updateSuffixColumnWidth: vi.fn(),
|
||||
createSuffixDir: vi.fn(),
|
||||
renameSuffixDir: vi.fn(),
|
||||
moveSuffixDir: vi.fn(),
|
||||
@@ -97,7 +98,7 @@ describe('SuffixPanel', () => {
|
||||
vi.mocked(createSuffixColumn).mockResolvedValue(ok({ id: 9, name: '招标人', is_value: true }) as never)
|
||||
await wrapper.findAll('button').find((b) => b.text() === '确定')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(createSuffixColumn).toHaveBeenCalledWith(2, '招标人', true)
|
||||
expect(createSuffixColumn).toHaveBeenCalledWith(2, '招标人', true, 0, 0)
|
||||
})
|
||||
|
||||
it('lists workspace rows grouped by province with fixed 锚定行 column', async () => {
|
||||
|
||||
@@ -4,8 +4,8 @@ import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
buildValueCell, createSuffix, createSuffixColumn, createSuffixDir, createSuffixGroup,
|
||||
deleteSuffix, deleteSuffixColumn, deleteSuffixDir, deleteSuffixFile, deleteSuffixGroup,
|
||||
formatSuffixSize, getSuffixOverview, getSuffixPage, getSuffixTree, moveSuffix, moveSuffixDir,
|
||||
moveSuffixGroup, parseValueCell, readSuffixFile, renameSuffix, renameSuffixDir,
|
||||
updateSuffixColumnWidth, formatSuffixSize, getSuffixOverview, getSuffixPage, getSuffixTree, moveSuffix, moveSuffixDir,
|
||||
moveSuffixGroup, parseValueCell, readSuffixFile, renameSuffixDir,
|
||||
renameSuffixGroup, reorderSuffixColumns, saveSuffixCell, setSuffixAnchor, suffixFileUrl, uploadSuffixFile,
|
||||
type SuffixColumn, type SuffixDir, type SuffixFile, type SuffixPage,
|
||||
} from '../suffix-admin'
|
||||
@@ -21,16 +21,13 @@ const pageLoading = ref(false)
|
||||
const overviewLoading = ref(false)
|
||||
|
||||
// 增加列弹框(列名 + 值设置复选框)
|
||||
const colDialog = reactive({ visible: false, name: '', isValue: false, saving: false })
|
||||
const colDialog = reactive({ visible: false, name: '', isValue: false, width: 0, saving: false })
|
||||
const dirCollapsed = ref(localStorage.getItem('suffixDirCollapsed') === '1')
|
||||
function toggleDirFold() { dirCollapsed.value = !dirCollapsed.value; try { localStorage.setItem('suffixDirCollapsed', dirCollapsed.value ? '1' : '0') } catch {} }
|
||||
// 单元格编辑
|
||||
const editing = reactive({ sid: 0, cid: 0, text: '', a: '', v: '' })
|
||||
// 行编辑态(视觉高亮,格子弹出编辑不受它限制)
|
||||
const editRows = ref<Set<number>>(new Set())
|
||||
// 后缀行内改名
|
||||
const renamingSuffix = ref(0)
|
||||
const renamingSuffixName = ref('')
|
||||
// 上传
|
||||
const uploadInput = ref<HTMLInputElement | null>(null)
|
||||
const uploadTarget = ref(0)
|
||||
@@ -164,15 +161,31 @@ async function moveDir(dir: SuffixDir, dirNum: number) {
|
||||
|
||||
// ---- 基本设置:分组与后缀 ----
|
||||
|
||||
async function addGroup() {
|
||||
const { value } = await ElMessageBox.prompt('输入分组名称(如:广东省)', '新建分组', { inputPattern: /\S/, inputErrorMessage: '名称不能为空' }).catch(() => ({ value: '' }))
|
||||
if (!value) return
|
||||
const groupDialog = reactive({ visible: false, name: '', suffixName: '', saving: false })
|
||||
|
||||
function addGroup() {
|
||||
groupDialog.name = ''
|
||||
groupDialog.suffixName = ''
|
||||
groupDialog.visible = true
|
||||
}
|
||||
|
||||
async function submitGroup() {
|
||||
if (groupDialog.saving) return
|
||||
const name = groupDialog.name.trim()
|
||||
if (!name) {
|
||||
ElMessage.warning('请填写分组名')
|
||||
return
|
||||
}
|
||||
groupDialog.saving = true
|
||||
try {
|
||||
await createSuffixGroup(value.trim())
|
||||
await createSuffixGroup(name, groupDialog.suffixName.trim())
|
||||
groupDialog.visible = false
|
||||
await loadOverview()
|
||||
ElMessage.success('分组已创建')
|
||||
ElMessage.success(groupDialog.suffixName.trim() ? '分组已创建(含一行后缀)' : '分组已创建')
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : '创建失败')
|
||||
} finally {
|
||||
groupDialog.saving = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,23 +222,13 @@ async function removeGroup(g: { id:number; name:string }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function insertSuffixTop(groupId: number) {
|
||||
async function insertSuffixRow(groupId: number, afterId: number, title: string) {
|
||||
const { value } = await ElMessageBox.prompt('输入后缀名(同名自动 -1,创建后不可修改)', title, { inputPattern: /\S/, inputErrorMessage: '名称不能为空' }).catch(() => ({ value: '' }))
|
||||
if (!value) return
|
||||
try {
|
||||
const created = (await createSuffix(groupId, 0)).data.data
|
||||
renamingSuffix.value = created.id
|
||||
renamingSuffixName.value = ''
|
||||
await loadOverview()
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : '插入失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function insertSuffixAfter(groupId: number, afterId: number) {
|
||||
try {
|
||||
const created = (await createSuffix(groupId, afterId)).data.data
|
||||
renamingSuffix.value = created.id
|
||||
renamingSuffixName.value = ''
|
||||
const created = (await createSuffix(groupId, value.trim(), afterId)).data.data
|
||||
await loadOverview()
|
||||
ElMessage.success(`后缀「${created.name}」已创建`)
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : '插入失败')
|
||||
}
|
||||
@@ -253,24 +256,6 @@ async function removeSuffix(s: { id:number; name:string }) {
|
||||
}
|
||||
}
|
||||
|
||||
function startRename(id: number, name: string) {
|
||||
renamingSuffix.value = id
|
||||
renamingSuffixName.value = name
|
||||
}
|
||||
|
||||
async function commitRename() {
|
||||
const id = renamingSuffix.value
|
||||
const name = renamingSuffixName.value.trim()
|
||||
renamingSuffix.value = 0
|
||||
if (!id) return
|
||||
try {
|
||||
await renameSuffix(id, name)
|
||||
await loadOverview()
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : '改名失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function onUploadPicked(event: Event) {
|
||||
const input = event.target as HTMLInputElement
|
||||
const file = input.files?.[0]
|
||||
@@ -278,6 +263,13 @@ async function onUploadPicked(event: Event) {
|
||||
const suffixId = uploadTarget.value
|
||||
uploadTarget.value = 0
|
||||
if (!file || !suffixId) return
|
||||
const row = groups.value.flatMap((g) => g.suffixes).find((s) => s.id === suffixId)
|
||||
const base = (row?.name || '').replace(/-\d+$/, '').toLowerCase()
|
||||
const ext = file.name.includes('.') ? file.name.split('.').pop()!.toLowerCase() : ''
|
||||
if (!base || ext !== base) {
|
||||
ElMessage.error(`上传文件的扩展名必须与本行后缀一致:本行是「${row?.name}」,只能上传 .${base || '?'} 文件`)
|
||||
return
|
||||
}
|
||||
uploading.value = true
|
||||
try {
|
||||
const payload = await readSuffixFile(file)
|
||||
@@ -316,6 +308,7 @@ async function openAddColumn() {
|
||||
if (selected.value.kind !== 'dir') return
|
||||
colDialog.name = ''
|
||||
colDialog.isValue = false
|
||||
colDialog.width = 0
|
||||
colDialog.visible = true
|
||||
}
|
||||
|
||||
@@ -334,6 +327,30 @@ function openColOrder() {
|
||||
colOrder.visible = true
|
||||
}
|
||||
|
||||
function colWidthOf(id: number): number {
|
||||
return pageColumns.value.find((c) => c.id === id)?.width || 0
|
||||
}
|
||||
|
||||
async function setColWidth(id: number, event: Event) {
|
||||
const w = parseInt((event.target as HTMLInputElement).value, 10)
|
||||
if (Number.isNaN(w) || w < 0 || w > 2000) {
|
||||
ElMessage.warning('列宽须为 0–2000(0=自适应)')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await updateSuffixColumnWidth(id, w)
|
||||
const col = pageColumns.value.find((c) => c.id === id)
|
||||
if (col) col.width = w
|
||||
ElMessage.success('列宽已保存')
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : '列宽保存失败')
|
||||
}
|
||||
}
|
||||
|
||||
function colStyle(col: SuffixColumn) {
|
||||
return col.width > 0 ? { width: col.width + 'px', minWidth: col.width + 'px', maxWidth: col.width + 'px' } : undefined
|
||||
}
|
||||
|
||||
async function moveColOrder(id: number, dir: number) {
|
||||
const sel = selected.value
|
||||
if (sel.kind !== 'dir' || !page.value) return
|
||||
@@ -380,7 +397,7 @@ async function submitColumn() {
|
||||
}
|
||||
colDialog.saving = true
|
||||
try {
|
||||
const created = (await createSuffixColumn(selected.value.id, name, colDialog.isValue)).data.data
|
||||
const created = (await createSuffixColumn(selected.value.id, name, colDialog.isValue, 0, colDialog.width)).data.data
|
||||
page.value?.columns.push(created)
|
||||
colDialog.visible = false
|
||||
ElMessage.success(colDialog.isValue ? `已添加值列「${created.name}」,点击它的单元格即可填写值设置` : `已添加列「${created.name}」`)
|
||||
@@ -544,51 +561,60 @@ onMounted(() => {
|
||||
<el-button size="small" @click="addGroup">+ 新建分组</el-button>
|
||||
</div>
|
||||
<div v-loading="overviewLoading" class="sheet-wrap">
|
||||
<div v-for="g in groups" :key="g.id" class="group-block">
|
||||
<div class="group-head">
|
||||
<span class="tw off">▾</span>
|
||||
<strong class="g-name" title="双击重命名" @dblclick="renameGroup(g.id, g.name)">{{ g.name }}</strong>
|
||||
<table class="sheet basic">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="b-idx">序号</th>
|
||||
<th class="b-suffix">后缀</th>
|
||||
<th class="b-files">导入文件</th>
|
||||
<th class="b-ops">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-for="g in groups" :key="g.id">
|
||||
<tr class="group-tr">
|
||||
<td class="group-cell" colspan="2">
|
||||
<span class="tw off">▾</span><strong>{{ g.name }}</strong>
|
||||
<span class="muted">{{ g.suffixes.length }} 个</span>
|
||||
<span class="grow"></span>
|
||||
<button type="button" class="op" title="在这个分组最前面插入一个后缀" @click="insertSuffixTop(g.id)">插入后缀</button>
|
||||
</td>
|
||||
<td></td>
|
||||
<td class="group-ops">
|
||||
<button type="button" class="op" title="上移" @click="moveGroup(g.id, -1)">↑</button>
|
||||
<button type="button" class="op" title="下移" @click="moveGroup(g.id, 1)">↓</button>
|
||||
<button type="button" class="op danger" title="删除分组" @click="removeGroup(g)">×</button>
|
||||
</div>
|
||||
<div v-for="(s, i) in g.suffixes" :key="s.id" class="suffix-row">
|
||||
<span class="c-idx">{{ i + 1 }}</span>
|
||||
<span class="c-suffix">
|
||||
<template v-if="renamingSuffix === s.id">
|
||||
<input
|
||||
v-model="renamingSuffixName"
|
||||
class="cell-input"
|
||||
autofocus
|
||||
@keyup.enter="commitRename"
|
||||
@blur="commitRename"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="suffix-name" :class="{ empty: !s.name }" title="双击重命名" @dblclick="startRename(s.id, s.name)">{{ s.name || '(双击命名)' }}</span>
|
||||
</template>
|
||||
</span>
|
||||
<span class="c-files">
|
||||
<button type="button" class="op danger" title="删除分组(连同后缀与模板文件)" @click="removeGroup(g)">×</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-for="(s, i) in g.suffixes" :key="s.id" class="data-tr">
|
||||
<td class="b-idx">{{ i + 1 }}</td>
|
||||
<td>
|
||||
<span class="suffix-name">{{ s.name || '—' }}</span>
|
||||
</td>
|
||||
<td class="files-cell">
|
||||
<span v-for="f in s.files" :key="f.id" class="file-chip">
|
||||
<a :href="suffixFileUrl(f.id)" target="_blank" rel="noopener" :title="`下载 ${f.file_name}(${formatSuffixSize(f.file_size)})`">{{ f.file_name }}</a>
|
||||
<button type="button" class="chip-x" title="删除模板" @click="removeFile(f)">×</button>
|
||||
</span>
|
||||
<span v-if="!s.files.length" class="muted">—</span>
|
||||
</span>
|
||||
<span class="c-ops">
|
||||
</td>
|
||||
<td class="ops-cell">
|
||||
<button type="button" class="btn-main" :disabled="uploading" @click="pickUpload(s.id)">上传模板</button>
|
||||
<button type="button" class="op" title="在这行下面插入一行" @click="insertSuffixAfter(g.id, s.id)">向下插入行</button>
|
||||
<button type="button" class="op" title="在这行下面插入一行(同名自动 -1)" @click="insertSuffixRow(g.id, s.id, '插入后缀')">向下插入行</button>
|
||||
<button type="button" class="op" title="上移" @click="moveSuffixRow(s.id, -1)">↑</button>
|
||||
<button type="button" class="op" title="下移" @click="moveSuffixRow(s.id, 1)">↓</button>
|
||||
<button type="button" class="op danger" title="删除后缀" @click="removeSuffix(s)">×</button>
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="!g.suffixes.length" class="suffix-row empty-row"><span class="c-idx">—</span><span class="muted">这个分组还没有后缀,</span><button type="button" class="op" @click="insertSuffixTop(g.id)">插入后缀</button></div>
|
||||
</div>
|
||||
<div v-if="!groups.length" class="empty-tip">还没有分组,点右上角「+ 新建分组」开始。</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!g.suffixes.length" class="data-tr">
|
||||
<td class="b-idx">—</td>
|
||||
<td><span class="muted">这个分组还没有后缀,</span><button type="button" class="op" @click="insertSuffixRow(g.id, 0, '插入后缀')">插入后缀</button></td>
|
||||
<td class="files-cell"><span class="muted">—</span></td>
|
||||
<td class="ops-cell"></td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-if="!groups.length"><td colspan="4" class="empty-tip">还没有分组,点右上角「+ 新建分组」开始(新分组自动带一行后缀)。</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -609,7 +635,7 @@ onMounted(() => {
|
||||
<th class="fix">后缀</th>
|
||||
<th class="fix">操作</th>
|
||||
<th class="fix">锚定行</th>
|
||||
<th v-for="col in pageColumns" :key="col.id" class="custom-th">
|
||||
<th v-for="col in pageColumns" :key="col.id" class="custom-th" :style="colStyle(col)">
|
||||
<span :title="col.is_value ? '值列:点单元格填 锚点+值' : col.name">{{ col.name }}<em v-if="col.is_value" class="vtag">值</em></span>
|
||||
<button type="button" class="th-x" title="删除列" @click="removeColumn(col)">×</button>
|
||||
</th>
|
||||
@@ -632,6 +658,7 @@ onMounted(() => {
|
||||
v-for="col in pageColumns"
|
||||
:key="col.id"
|
||||
class="cell"
|
||||
:style="colStyle(col)"
|
||||
:class="{ locked: !editRows.has(row.sid) }"
|
||||
@dblclick="startCellEdit(row.sid, col)"
|
||||
:title="editRows.has(row.sid) ? '双击编辑' : '先点这一行的「编辑」,再双击单元格'"
|
||||
@@ -675,6 +702,9 @@ onMounted(() => {
|
||||
<el-checkbox v-model="colDialog.isValue">值设置</el-checkbox>
|
||||
<span class="muted">勾选后该列为值列,点击单元格可填写 锚点+值;不勾选则为普通列,不可填值设置。</span>
|
||||
</label>
|
||||
<label><span class="lab">列宽(px,0=自适应)</span>
|
||||
<el-input v-model.number="colDialog.width" type="number" :min="0" :max="2000" />
|
||||
</label>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="colDialog.visible = false">取消</el-button>
|
||||
@@ -682,6 +712,22 @@ onMounted(() => {
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="groupDialog.visible" title="新建分组" width="440px">
|
||||
<div class="col-form">
|
||||
<label><span class="lab">分组名(分类名)</span>
|
||||
<el-input v-model="groupDialog.name" placeholder="例如:广东省" maxlength="190" @keyup.enter="submitGroup" />
|
||||
</label>
|
||||
<label><span class="lab">首个后缀名</span>
|
||||
<el-input v-model="groupDialog.suffixName" placeholder="例如:cos4(留空则暂不建行)" maxlength="64" />
|
||||
</label>
|
||||
<p class="muted">分组建好后自动带一行工作行;行名按后缀命名,同名自动 -1,创建后不可修改。</p>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="groupDialog.visible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="groupDialog.saving" @click="submitGroup">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="colOrder.visible" title="列排序" width="480px">
|
||||
<div class="col-order-hint">拖动调整列的左右顺序;值列以蓝色字体显示。也可以在这里精准添加列:填列名、勾选值设置,新列会插到选中列的后面(未选中则加到最右)。</div>
|
||||
<div class="col-order-list">
|
||||
@@ -696,6 +742,16 @@ onMounted(() => {
|
||||
<span class="co-name" :class="{ value: pageColumns.find((c) => c.id === cid)?.is_value }">{{ pageColumns.find((c) => c.id === cid)?.name }}</span>
|
||||
<span v-if="pageColumns.find((c) => c.id === cid)?.is_value" class="co-vtag">值</span>
|
||||
<span class="grow"></span>
|
||||
<input
|
||||
class="co-width"
|
||||
type="number"
|
||||
min="0"
|
||||
max="2000"
|
||||
:value="colWidthOf(cid)"
|
||||
title="列宽 px(0=自适应)"
|
||||
@click.stop
|
||||
@change="setColWidth(cid, $event)"
|
||||
/>
|
||||
<button type="button" class="op" :disabled="i === 0" @click.stop="moveColOrder(cid, -1)">↑</button>
|
||||
<button type="button" class="op" :disabled="i === colOrder.ids.length - 1" @click.stop="moveColOrder(cid, 1)">↓</button>
|
||||
</div>
|
||||
@@ -713,7 +769,7 @@ onMounted(() => {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.suffix-shell{display:flex;gap:14px;height:calc(100vh - 104px);align-items:stretch;position:relative;overflow:hidden}
|
||||
.suffix-shell{display:flex;gap:8px;height:calc(100vh - 88px);align-items:stretch;position:relative;overflow:hidden}
|
||||
.dir-fold{position:fixed;left:527px;top:50%;transform:translateY(-50%);z-index:30;width:18px;height:52px;border:1px solid #d8dfe8;border-left:0;border-radius:0 6px 6px 0;background:#fff;color:#526173;cursor:pointer;display:grid;place-items:center;font-size:12px}
|
||||
.admin-workspace.nav-collapsed .dir-fold{left:285px}
|
||||
.dir-fold.collapsed{left:252px}
|
||||
@@ -738,7 +794,7 @@ onMounted(() => {
|
||||
.side-count{margin-left:0;color:#9aa7b6;font-size:11px;flex:0 0 auto}
|
||||
.side-plus{margin-left:auto;color:#1769e0;cursor:pointer;font-weight:700}
|
||||
.suffix-main{flex:1;min-width:0;height:100%;display:flex;flex-direction:column;overflow:hidden}
|
||||
.bar{display:flex;align-items:center;gap:12px;padding:0 0 10px}
|
||||
.bar{display:flex;align-items:center;gap:8px;padding:0 0 6px}
|
||||
.bar strong{font-size:15px}
|
||||
.bar-note{color:#8a97a8;font-size:12px}
|
||||
/* 列排序弹框 */
|
||||
@@ -751,11 +807,23 @@ onMounted(() => {
|
||||
.co-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.co-name.value{color:#1769e0;font-weight:600}
|
||||
.co-vtag{font-style:normal;background:#e6f5ee;color:#16845b;border-radius:3px;font-size:10px;padding:0 4px}
|
||||
.co-width{width:58px;text-align:center;font-size:12px;border:1px solid #d8dfe8;border-radius:3px;padding:1px 4px}
|
||||
.col-order-add{display:flex;align-items:center;gap:10px;margin-top:12px}
|
||||
.col-order-add .el-input{flex:1}
|
||||
td.cell.locked{cursor:default}
|
||||
.grow{flex:1}
|
||||
.sheet-wrap{flex:1;min-height:0;border:1px solid #e5eaf0;border-radius:6px;overflow:auto;background:#fff}
|
||||
table.sheet.basic{border-collapse:collapse;width:100%;font-size:13px}
|
||||
table.sheet.basic th,table.sheet.basic td{border:1px solid #dfe5e7;padding:2px 8px;height:26px;text-align:left;vertical-align:middle}
|
||||
table.sheet.basic thead th{background:#f4f6fa;font-weight:600;height:28px}
|
||||
table.sheet.basic .b-idx{width:56px;text-align:center;color:#9aa7b6}
|
||||
table.sheet.basic .b-suffix{min-width:150px}
|
||||
table.sheet.basic .group-tr td{background:#f4f6fa}
|
||||
table.sheet.basic .group-cell strong{font-size:13px}
|
||||
table.sheet.basic .group-ops{text-align:right;white-space:nowrap}
|
||||
table.sheet.basic .ops-cell{white-space:nowrap}
|
||||
table.sheet.basic .files-cell{min-width:220px}
|
||||
table.sheet.basic tr.data-tr:hover td{background:#fafcff}
|
||||
.group-block{border-bottom:1px solid #eef1f5}
|
||||
.group-block:last-child{border-bottom:0}
|
||||
.group-head{display:flex;align-items:center;gap:8px;padding:8px 12px;background:#f4f6fa;border-bottom:1px solid #eef1f5}
|
||||
@@ -784,8 +852,8 @@ td.cell.locked{cursor:default}
|
||||
.c-ops{display:flex;gap:6px;flex:0 0 auto}
|
||||
.empty-tip{padding:26px;text-align:center;color:#9aa7b6;font-size:13px}
|
||||
.hidden-file{display:none}
|
||||
table.sheet{border-collapse:collapse;width:100%;font-size:13px}
|
||||
table.sheet th,table.sheet td{border-right:1px solid #eef1f5;border-bottom:1px solid #eef1f5;padding:6px 10px;text-align:left;white-space:nowrap}
|
||||
table.sheet{border-collapse:collapse;width:100%;font-size:12.5px}
|
||||
table.sheet th,table.sheet td{border-right:1px solid #eef1f5;border-bottom:1px solid #eef1f5;padding:3px 8px;text-align:left;white-space:nowrap}
|
||||
table.sheet thead th{background:#f4f6fa;color:#657387;font-weight:600;position:relative}
|
||||
.fix{background:#fff}
|
||||
thead .fix{background:#f4f6fa}
|
||||
|
||||
Reference in New Issue
Block a user