diff --git a/server/internal/api/templates.go b/server/internal/api/templates.go index d8c6beb..645ccaa 100644 --- a/server/internal/api/templates.go +++ b/server/internal/api/templates.go @@ -109,8 +109,8 @@ func (api *TemplatesAPI) createTemplate(w http.ResponseWriter, r *http.Request) r = WithPayload(r, payload) - // 介URL参数获取用户ID - if userIDStr := r.URL.Query().Get("userId"); userIDStr != "" { + // 从 URL 参数获取用户ID + if userIDStr := r.URL.Query().Get("current_user_id"); userIDStr != "" { var userID uint64 if _, scanErr := fmt.Sscan(userIDStr, &userID); scanErr == nil && userID > 0 { payload.OwnerID = userID @@ -152,7 +152,7 @@ func (api *TemplatesAPI) createTemplate(w http.ResponseWriter, r *http.Request) // listTemplates 获取模板列表 func (api *TemplatesAPI) listTemplates(w http.ResponseWriter, r *http.Request) { - userIDStr := r.URL.Query().Get("userId") + userIDStr := r.URL.Query().Get("current_user_id") // 构建查询SQL querySQL := `SELECT id, name, datasource, main_table, file_format, visibility, @@ -387,6 +387,18 @@ func (api *TemplatesAPI) patchTemplate(w http.ResponseWriter, r *http.Request, t // deleteTemplate 删除模板 func (api *TemplatesAPI) deleteTemplate(w http.ResponseWriter, r *http.Request, templateID string) { + // 检查是否为公共模板(owner_id=0) + var ownerID uint64 + rowOwner := api.metaDB.QueryRow("SELECT owner_id FROM export_templates WHERE id=?", templateID) + if err := rowOwner.Scan(&ownerID); err != nil { + fail(w, r, http.StatusNotFound, "template not found") + return + } + if ownerID == 0 { + fail(w, r, http.StatusForbidden, "公共模板不允许删除") + return + } + // 检查是否有关联的导出任务 var jobCount int64 row := api.metaDB.QueryRow("SELECT COUNT(1) FROM export_jobs WHERE template_id=?", templateID) diff --git a/web/index.html b/web/index.html index 59194e7..18e3e37 100644 --- a/web/index.html +++ b/web/index.html @@ -45,7 +45,7 @@ size="small" @click="openEdit(scope.row)">编辑 删除 diff --git a/web/modules/api.js b/web/modules/api.js index d524e7d..3970792 100644 --- a/web/modules/api.js +++ b/web/modules/api.js @@ -41,13 +41,13 @@ const getMerchantId = () => { /** * 构建用户相关的查询字符串 - * @returns {string} 查询字符串,如 '?userId=1&merchantId=2' + * @returns {string} 查询字符串,如 '?current_user_id=1&merchantId=2' */ const buildUserQueryString = () => { const userId = getUserId(); const merchantId = getMerchantId(); const parts = []; - if (userId) parts.push('userId=' + encodeURIComponent(userId)); + if (userId) parts.push('current_user_id=' + encodeURIComponent(userId)); if (merchantId) parts.push('merchantId=' + encodeURIComponent(merchantId)); return parts.length ? ('?' + parts.join('&')) : ''; }; @@ -95,6 +95,7 @@ const get = async (endpoint, options = {}) => { const userId = getUserId(); const merchantId = getMerchantId(); if (userId) queryParams.set('userId', userId); + if (userId) queryParams.set('current_user_id', userId); if (merchantId) queryParams.set('merchantId', merchantId); }