常见问题处理

1、上传图片失败?
处理方法:
检查数据库中是否有sys_attachment 表,没有的话执行下面sql增加

CREATE TABLE `sys_attachment` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '文件ID',
  `app_id` varchar(64) NOT NULL COMMENT '应用ID',
  `drive` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '上传驱动',
  `name` varchar(1000) DEFAULT NULL COMMENT '文件原始名',
  `kind` varchar(16) DEFAULT NULL COMMENT '上传类型',
  `mime_type` varchar(128) NOT NULL DEFAULT '' COMMENT '扩展类型',
  `path` varchar(1000) DEFAULT NULL COMMENT '本地路径',
  `size` bigint(20) DEFAULT '0' COMMENT '文件大小',
  `ext` varchar(50) DEFAULT NULL COMMENT '扩展名',
  `md5` varchar(32) DEFAULT NULL COMMENT 'md5校验码',
  `created_by` bigint(20) DEFAULT '0' COMMENT '上传人ID',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态',
  `created_at` datetime DEFAULT NULL COMMENT '创建时间',
  `updated_at` datetime DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `md5` (`md5`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=157 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='附件管理';

1、上传后的图片看不到?
处理方式:
检查 internal/app/common/logic/upload/upload.go 文件 中的 UploadFile方法是否和下面一样

func (s *sUpload) UploadFile(ctx context.Context,
    file *ghttp.UploadFile, checkFileType string, source int,
    userId uint64, appId string) (result *model.UploadResponse, err error) {
    err = g.Try(ctx, func(ctx context.Context) {
        // 检查文件类型
        err = s.CheckType(ctx, checkFileType, file.Filename)
        liberr.ErrIsNil(ctx, err)

        // 检查文件大小
        err = s.CheckSize(ctx, checkFileType, file.Size)
        liberr.ErrIsNil(ctx, err)
        //判断该文件是否已经上传过,上传过则不再上传
        var (
            md5        = ""
            existsFile *model.SysAttachmentInfoRes
        )
        md5, err = s.computeMD5(file)
        liberr.ErrIsNil(ctx, err)
        existsFile, err = service.SysAttachment().GetByMd5(ctx, md5)
        liberr.ErrIsNil(ctx, err, "获取文件信息失败")
        if existsFile != nil {
            if !gfile.Exists(g.Cfg().MustGet(ctx, "server.serverRoot").String() + "/" + existsFile.Path) {
                // 文件不存在,删除sysAttachment表中不存在的条目
                service.SysAttachment().Delete(ctx, []int64{existsFile.Id})
            } else {
                result = &model.UploadResponse{
                    Size:     existsFile.Size,
                    Path:     existsFile.Path,
                    FullPath: libUtils.GetDomain(ctx, true) + "/" + existsFile.Path,
                    Name:     existsFile.Name,
                    Type:     existsFile.MimeType,
                }
                return
            }
        }
        uploader := upload.GetUploader(upload.UploaderType(source))
        if uploader == nil {
            liberr.ErrIsNil(ctx, errors.New("没有找到上传适配器"))
        }
        result, err = uploader.Upload(ctx, file)
        liberr.ErrIsNil(ctx, err)
        //保存上传文件到数据库
        err = service.SysAttachment().AddUpload(ctx, result, &model.SysAttachmentAddAttribute{
            Md5:    md5,
            Driver: gconv.Uint(source),
            UserId: userId,
            AppId:  appId,
        })
        liberr.ErrIsNil(ctx, err)
    })
    return
}

2、富文本编辑器的弹出窗口有错不显示或显示首页的问题
处理方式:
检查对比管理端UI代码中的 src/components/ueditor/index.vue

<template>
  <div class="ue-content">
    <vue-ueditor-wrap v-model="html" :config="editorConfig" :editor-id="editorId"
                      :editorDependencies="['ueditor.config.js','ueditor.all.js']"></vue-ueditor-wrap>
  </div>
</template>


<script lang="ts">
import { getToken,baseURL } from '/@/utils/gfast';
import {defineComponent, reactive, computed} from "vue";
import {toolbar} from "/@/components/ueditor/model";

export default defineComponent({
  name:'GfUeditor',
  props: {
    editorId: {
      type: String,
      default: 'vueEditorId01'
    },
    modelValue: {
      type: String,
      default: ''
    },
    ueditorConfig: {
      type: Object,
      default(){
        return {
          initialFrameWidth: '100%',
          initialFrameHeight: 400,
          maximumWords: 5000,
          topOffset: 80,
          zIndex:2050
        }
      }
    },
    toolBars: {
      type: Array,
      default() {
        return toolbar
      }
    }
  },
  emits:['update:modelValue'],
  setup(props,{emit}){
    const config = Object.assign({
      elementPathEnabled: false,
      maximumWords: 10000,
      headers: {
        Authorization: 'Bearer ' + getToken()
      },
      toolbars: [props.toolBars],
      UEDITOR_HOME_URL: import.meta.env.BASE_URL + "js/ueditor/", // 访问 UEditor 静态资源的根路径,可参考常见问题1
      UEDITOR_CORS_URL: import.meta.env.BASE_URL + "js/ueditor/", // 访问 UEditor 静态资源的根路径,可参考常见问题1
      serverUrl: baseURL+'api/v1/system/uEditor/action?token='+encodeURIComponent(getToken()), // 服务端接口(这个地址是我为了方便各位体验文件上传功能搭建的临时接口,请勿在生产环境使用!!!)
    },props.ueditorConfig)
    const editorConfig = reactive(config)
    const html =computed({
      get:()=>{
        return props.modelValue
      },
      set:(newVal)=>{
        emit('update:modelValue',newVal)
      }
    })
    return {
      html,
      editorConfig
    }
  },
  unmounted() {
    window.document.getElementById(this.editorId)?.remove()
  }
})
</script>

<style scoped>
.ue-content{line-height: normal!important;width: 100%;}
.ue-content .ue-container{

}
</style>

3、字典缺少 cms_ad_type 导致广告类型找不到
处理方法:可以自己在数据中增加

insert into `sys_dict_type` (`dict_name`, `dict_type`, `status`, `create_by`, `update_by`, `remark`, `created_at`, `updated_at`) values('CMS广告类型','cms_ad_type','1','31','0','','2023-03-02 09:35:27','2023-03-02 09:35:27');
insert into `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `update_by`, `remark`, `created_at`, `updated_at`) values('0','图片','image','cms_ad_type','','','1','1','31','0','','2023-03-02 09:37:10','2023-03-02 09:37:10');
insert into `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `update_by`, `remark`, `created_at`, `updated_at`) values('0','JS代码','js','cms_ad_type','','','0','1','31','0','','2023-03-02 09:37:27','2023-03-02 09:37:27');
insert into `sys_dict_data` (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `update_by`, `remark`, `created_at`, `updated_at`) values('0','文本','text','cms_ad_type','','','0','1','31','0','','2023-03-02 09:37:39','2023-03-02 09:37:39');
作者:袁学飞  创建时间:2025-06-25 09:41
最后编辑:袁学飞  更新时间:2025-06-25 11:13