-- 只更新表单和自定义表单的JS增强，不更新其他信息
DELETE FROM "LOWCODE_FRAME"."LOWCODE_DBFORM_ENHANCE_JS" WHERE DBFORM_ID IN (SELECT ID FROM "LOWCODE_FRAME"."LOWCODE_DBFORM" WHERE TABLE_NAME IN ('lc_basic_safety_information') AND IS_DELETED = 0);
insert into "LOWCODE_FRAME"."LOWCODE_DBFORM_ENHANCE_JS"("ID", "TENANT_ID", "CREATE_USER", "CREATE_TIME", "CREATE_DEPT", "UPDATE_USER", "UPDATE_TIME", "IS_DELETED", "DBFORM_ID", "JS_TYPE", "JS_JSON") values(1966513983428063233, 1, 1, '2025-09-12 22:47:24', 100, 1, '2025-11-07 13:29:31', 0, 1966386366515343361, 'js', 'function isNotEmptyArray(arr) {
  return Array.isArray(arr) && arr.length > 0;
}

function downloadFile(url, fileName) {
  const xhr = new XMLHttpRequest();
  xhr.open(''GET'', url);
  xhr.responseType = ''blob'';
  xhr.onload = function () {
    const blob = xhr.response;
    const link = document.createElement(''a'');
    link.href = URL.createObjectURL(blob);
    link.download = fileName;
    link.click();
  };
  xhr.send();
}

function getFileName(url) {
  const segments = url.split(''/'').filter(Boolean);
  return segments[segments.length - 1] || '''';
}

return {
  initOption() { //表格显示前执行
    // 修改资料分类的名称（分别为搜索栏以及表格列）
    useFun.requestApi(''get'', ''/system/dict-data/page'', {
      params: {
        "dictType": ''basic_safety_main_category'',
        "pageNo": 1,
        "pageSize": -1
      }
    }).then(res => {
      let dictData = res.list

      let dataMap = {};
      dictData.forEach(item => {
        dataMap[item.value] = item.label
      })
      let file_main_name = dataMap[props.fixedSearch.file_main_type]
      if (file_main_name != null && file_main_name != undefined) {
        tableOption.value.column.file_sub_type.label = file_main_name + ''分类''
        tableOption.value.column.file_sub_type_name.label = file_main_name + ''分类''
      } else {
        tableOption.value.column.file_sub_type.label = ''资料分类''
        tableOption.value.column.file_sub_type_name.label = ''资料分类''
      }
    })

    tableOption.value.column.create_user.label = ''上传人''
    tableOption.value.column.create_time.label = ''上传时间''
    tableOption.value.column.company_id.label = ''公司''
    tableOption.value.column.department_id.label = ''部门''

    // 处理一下二级分类的内容
    useFun.requestApi(''get'', ''/system/dict-data/page'', {
      params: {
        "dictType": ''basic_safety_sub_category'',
        "pageNo": 1,
        "pageSize": -1
      }
    }).then(res => {
      let filtered = res.list.filter(item => item.value.startsWith(props.fixedSearch.file_main_type))
      useFun.setPropConfig(''file_sub_type'', { dicData: filtered })
    })
  },
  async beforeFormData(formData, type) { //表单打开前执行
    // 将一级分类传给formData，这样就可以保存这个一级类型
    formData = {
      ...formData,
      ...props.fixedSearch,
    }

    // 将当前用户所在的公司，传递给表单，这样就可以默认了
    const userData = useFun.useUserStoreWithOut()
    if (isNotEmptyArray(userData.deptInfo)) {
      let res = await useFun.requestApi(''get'', `/system/dept/get-user-company`, {
        data: {}
      })
      if (res != null && res != undefined) {
        formData.company_id = res.id
        formData.company_name = res.name
      } else {
        // 查不到二级部门的情况也需要考虑，这样就考虑在哪个部门就把哪个部门设置为公司
        if (Array.isArray(userData.deptInfo) && userData.deptInfo.length > 0) {
          let dept = userData.deptInfo[0]
          formData.company_id = dept.deptId
          formData.company_name = dept.deptName
        }
      }
    }
    // 最终返回结果
    return new Promise((resolve, reject) => {
      resolve(formData);
    })
  },
  download_file(row) {
    // row.file_url 如何发起一个下载？
    downloadFile(row.file_url, getFileName(row.file_url))
  },
  delete_btn(row) {
    let ids = [row.id]
    let tableId = props.tableId
    useFun.requestApi(''delete'', `/jeelowcode/dbform-data/delete/${tableId}`, {
      data: ids
    }).then(() => {
      // 成功动作，刷新表单
      useFun.refreshChange()
    }).catch(() => {
      // 失败动作
      message.alert(''删除失败'', ''提示'', { type: ''info'' })
    })
  },
}');
DELETE FROM "LOWCODE_FRAME"."LOWCODE_DESFORM" WHERE ID IN (SELECT DESFORM_WEB_ID FROM "LOWCODE_FRAME"."LOWCODE_DBFORM" WHERE TABLE_NAME IN ('lc_basic_safety_information') AND IS_DELETED = 0);
insert into "LOWCODE_FRAME"."LOWCODE_DESFORM"("ID", "TENANT_ID", "CREATE_USER", "CREATE_TIME", "CREATE_DEPT", "UPDATE_USER", "UPDATE_TIME", "IS_DELETED", "DESFORM_NAME", "DESFORM_JSON", "GROUP_DESFORM_ID", "IS_OPEN", "IS_TEMPLATE", "IS_HIDE", "I18N_DATA") values(1966404735134167042, 1, 1, '2025-09-12 15:33:18', 100, 1, '2025-11-07 13:34:19', 0, '安全基础资料表', '{"jsEnhance":"return {\n  initData(formData) { //表单赋值前执行\n    return new Promise(async (resolve, reject) => {\n      let res = await useFun.requestApi(''get'', ''/system/dict-data/page'', {\n        params: {\n          \"dictType\": ''basic_safety_main_category'',\n          \"pageNo\": 1,\n          \"pageSize\": -1\n        }\n      })\n      let dictData = res.list\n      let dataMap = {};\n      dictData.forEach(item => {\n        dataMap[item.value] = item.label\n      })\n      let file_main_name = dataMap[formData.file_main_type]\n      if (file_main_name != undefined) {\n        useFun.setPropConfig(''file_sub_type'', { label: `${file_main_name}分类` })\n        formData.$file_main_type = file_main_name\n      } else {\n        useFun.setPropConfig(''file_sub_type'', { label: ''资料分类'' })\n      }\n\n      // 二级分类与一级分类相关联\n      useFun.requestApi(''get'', ''/system/dict-data/page'', {\n        params: {\n          \"dictType\": ''basic_safety_sub_category'',\n          \"pageNo\": 1,\n          \"pageSize\": -1\n        }\n      }).then(res => {\n        let filtered = res.list.filter(item => item.value.startsWith(formData.file_main_type))\n        let propConfig = useFun.getPropConfig(''file_sub_type'')\n        useFun.setPropConfig(''file_sub_type'', { dicData: filtered })\n      })\n      resolve(formData)\n    })\n  },\n  beforeSubmit(submitData) { //表单提交前执行\n    // 将属性名配置正常\n    submitData.department_name = formData.value.$department_id\n    submitData.file_sub_type_name = formData.value.$file_sub_type\n    submitData.file_main_type_name = formData.value.$file_main_type\n    return new Promise((resolve, reject) => {\n      resolve(submitData)\n    })\n  },\n}\n","scssEnhance":".low-form__1966404735134167042 {\n  padding: 0 0 !important;\n\n  .avue-form__group avue-form__group--flex {}\n\n  .el-card__body {\n    padding: unset !important;\n  }\n\n  .control-fields_2089442 {\n    min-width: 341px !important;\n    max-width: 341px !important;\n  }\n\n  .control-approveStatusName {\n    min-width: 64%;\n  }\n\n  .el-col-md-3 {\n    margin-left: 0 !important;\n  }\n\n  .control-fields_2642050 {\n    left: 90px;\n    min-width: 164px !important;\n    max-width: 164px !important;\n  }\n\n  .control-fields_9126239 {\n    left: 34px;\n    min-width: 164px !important;\n    max-width: 164px !important;\n  }\n\n  .control-create_time {\n    left: -49px;\n    top: 5px;\n\n    p {\n      margin: unset !important;\n    }\n  }\n\n  .control-billNo {\n    left: 2px;\n    bottom: -5px;\n    min-width: 234px !important;\n    max-width: 234px !important;\n\n    p {\n      margin: unset !important;\n    }\n  }\n\n  .avue-form.avue--detail {\n\n    .head_title,\n    .head_detail_label,\n    .head_detail_label,\n    .head_type_value,\n    .head_number_label,\n    .head_number_value,\n    .head_created_time_label,\n    .head_created_time_value,\n    .head_status_label,\n    .head_separator2,\n    .head_separator1 {\n      margin-top: unset !important;\n    }\n\n    .ce_class {\n      top: 7px !important;\n    }\n\n    .control-create_time {\n      left: -40px !important;\n      top: -6px !important;\n    }\n\n    * {\n      border: none !important;\n    }\n\n    .control-approveStatusName {\n      margin-top: 0 !important;\n      border: none !important;\n    }\n\n    .control-fields_9126239 {\n      left: 34px !important;\n      top: -11px;\n    }\n\n    .control-fields_2642050 {\n      left: 89px !important;\n      top: -11px;\n    }\n\n    .control-billNo {\n      left: 40 !important;\n      top: -5px !important;\n    }\n\n    .head_title {\n      border: none !important;\n    }\n  }\n\n  .bottom_class {\n    position: relative;\n    bottom: 31px;\n  }\n\n  .dash_class {\n    border-bottom: 1px dashed #999 !important;\n  }\n\n  //样式请写在当前位置内\n  // .el-collapse-content-873.avue-form__group {\n  //   border-bottom: 1px dashed #999;\n  // }\n  .avue-form__group {\n\n    .control-fields_7103563.head_title,\n    .control-fields_2247746.head_status_value {\n      line-height: 20px !important;\n      border: none !important;\n      font-weight: 700 !important;\n      color: #141414 !important;\n\n      .avue-title p {\n        font-size: 20px !important;\n      }\n\n    }\n\n    .control-fields_2247746.head_status_value {\n      // left: calc(16% + 25px);\n      color: green !important;\n      // color: #999;\n      font-size: 14px !important;\n\n      .avue-title p {\n        font-size: 14px !important;\n      }\n    }\n\n    .head_status_value {\n      margin-top: 30px !important;\n    }\n\n    .head_title,\n    .head_detail_label {\n      margin-left: 90px !important;\n      margin-top: 30px !important;\n    }\n\n    .head_detail_label,\n    .head_type_value,\n    .head_number_label,\n    .head_number_value,\n    .head_created_time_label,\n    .head_created_time_value,\n    .head_status_label,\n    .head_separator2,\n    .head_separator1 {\n      border: none !important;\n      color: #999 !important;\n      margin-top: -30px !important;\n\n      .avue-title p {\n        font-size: 14px !important;\n        font-weight: 400 !important;\n      }\n    }\n\n    .control-fields_3957948.head_type_value {\n      // left: calc(10% + 25px);\n    }\n\n    .head_separator1,\n    .head_separator2,\n    .head_separator3 {\n      line-height: 20px !important;\n      color: #C7C7C7 !important;\n    }\n\n    .control-fields_6000884.head_separator2 {\n      // left: calc(30% + 25px);\n    }\n\n    // .control-fields_5375235.head_separator3 {\n    //   left: 45%;\n    // }\n\n    .control-fields_2642050.head_number_label {\n      // left: calc(16% + 25px);\n    }\n\n    .control-fields_225062.head_number_value {\n      // left: calc(22% + 25px);\n    }\n\n    .control-fields_9126239.head_created_time_label {\n      // left: calc(31% + 25px);\n    }\n\n    .control-fields_4975109.head_created_time_value {\n      // left: calc(37% + 25px);\n\n      .avue-title p {\n        // width: 200px;\n      }\n    }\n\n    // .control-fields_7337553.head_status_label {\n    //   left: 43%;\n    // }\n\n\n\n    .ce_class {\n      min-width: 65px !important;\n      max-width: 65px !important;\n      min-height: 65px !important;\n      max-height: 65px !important;\n      background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAAB6CAYAAABne9ctAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAGdYAABnWARjRyu0AAAVc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fbWw815wKjKFVhatUdrU6qY9z/8nzgPGHUp84+CmXb/jHD/ZjWEyb/NOuf1OXvr4eZ8H3gva6GZOmhIQ6rGp1e4fkt+sWJewS68f9Ye2XTxFlwYhbmVzbGh03DmxNafcqPGf6JklavmysFCsbavxaL5eVfxAI407P7VmIn3qkkUXgZUtdOAwmlA4TSgcBpQOLcBg4M7OotbZY+TrUq4c8UpldDv7TRgev187jDYeo5nK5TMXd9b5SMsBe6H04D1KWitt0dl+mHCHjFmlmFiYecSXkd++/euOA2YqYOjjeYWeem+nYDvJrbfkj+7DF/dgCvT26fYriZob9j83iWnS2lgPo/lw2H4ecreIkuAeTKevA/6j5gPcr8+B+PzsGgtvr/5KJx7ArKp7eMuOA9YrsD3N+Gjqzt/UYlSdeadUyFQLO88uOltgXcGzWWtJI5jnE6hAJkUvNhj3m2Ucf5o7lWq5qDln9LOeE1Z88rrbk4mHkkEBHMgc/ak+QSmdCKPmLx8Bs4/CQNdyf6OzqfQrQolc8vDN+PmGZzYAzsUBNDTbP57noHOZOORdMAN12bgx9/hyl/mMlA1NPe1iBCY6TGbMkebzx6Hl3rMvTwH4UACbrW4CnPLO/cnvgowixPt6x/Gd9AOPKDan4RnbBU3DSicBhROAwqnAYXTgMJpQOE0oHAaUDgNKJwGFE4DCqcBhdOAwmlA4TSgcBpQOA0onAYUTgMKpwGF04DCaUDhNKBwGlA4DSicBhTuX6X4xrCOgSlsAAAAAElFTkSuQmCC\");\n      background-size: cover !important;\n      background-repeat: no-repeat !important;\n      border-radius: 20% !important;\n      position: absolute !important;\n      top: 30px !important;\n      margin-left: 20px !important;\n      z-index: 1 !important;\n    }\n\n    .el-collapse-item__content {\n      .avue-form__group {\n        // justify-content: center !important;\n      }\n    }\n\n    .el-form-item__content {\n      border: none !important;\n      padding: 0 !important;\n    }\n\n\n  }\n}","labelPosition":"right","labelSuffix":"","labelWidth":10,"gutter":0,"menuBtn":true,"submitBtn":true,"submitText":"提交","emptyBtn":true,"emptyText":"清空","externalTitle":"","menuPosition":"center","size":"default","isSubmitTable":true,"column":{},"tableDesignId":"1966386366515343361","group":[{"type":"layoutGroup","controlType":"layout","label":"基本信息","controlTip":"该布局只能放置在最底部","arrow":true,"collapse":true,"column":{"file_name":{"type":"input","controlType":"input","label":"资料名称","readonly":false,"clearable":true,"display":true,"span":22,"disabled":false,"required":true,"hideLabel":false,"i18nCode":"fields_867779","offset":1,"labelWidth":110,"verifyConfig":"[{\"label\":\"字符长度校验\",\"type\":\"leng\",\"controlType\":\"length\",\"leng_type\":\"all\",\"prop\":\"option_7505248\",\"display\":true,\"leng_max\":128}]"},"department_id":{"type":"deptSelect","controlType":"select","label":"所属部门","findType":"sub","display":true,"span":11,"disabled":false,"required":true,"hideLabel":false,"i18nCode":"fields_1781150","labelWidth":110,"textFormatter":"{dicText}({dicCode})","offset":1},"file_sub_type":{"type":"select","controlType":"select","label":"资料分类","clearable":true,"collapseTags":true,"maxCollapseTags":1,"dicType":"code","staticDicData":[{"label":"字典1","value":"dic_1"},{"label":"字典2","value":"dic_2"}],"display":true,"span":11,"disabled":false,"required":true,"hideLabel":false,"i18nCode":"fields_6672274","delDicValue":[],"offset":0,"labelWidth":110,"dicCode":"basic_safety_sub_category","codeDicData":[{"value":"0","label":"综合安全","colorType":"default","cssClass":""},{"value":"1","label":"专项安全","colorType":"default","cssClass":""},{"value":"2","label":"安全操作","colorType":"default","cssClass":""},{"value":"3","label":"层级化","colorType":"default","cssClass":""},{"value":"4","label":"配套支持","colorType":"default","cssClass":""}]},"visible_dept":{"type":"deptSelect","controlType":"select","label":"可见部门","findType":"all","display":true,"span":11,"disabled":false,"required":true,"hideLabel":false,"i18nCode":"fields_280965","textFormatter":"{dicText}({dicCode})","offset":1,"labelWidth":110,"multiple":true},"file_description":{"type":"textarea","controlType":"input","label":"资料内容描述","readonly":false,"minRows":3,"maxRows":5,"display":true,"span":22,"disabled":false,"required":false,"hideLabel":false,"i18nCode":"fields_3533958","labelWidth":110,"offset":1,"labelTip":"资料内容描述","verifyConfig":"[{\"label\":\"字符长度校验\",\"type\":\"leng\",\"controlType\":\"length\",\"leng_type\":\"all\",\"prop\":\"option_4419202\",\"display\":true,\"leng_max\":500}]"}},"display":true,"span":24,"hideLabel":false,"prop":"basic_info","i18nCode":"fields_5109620","className":"basic_info"},{"type":"layoutGroup","controlType":"layout","label":"上传资料","controlTip":"该布局只能放置在最底部","arrow":true,"collapse":true,"column":{"file_url":{"type":"file","controlType":"upload","label":"选择文件","showFileList":true,"display":true,"span":22,"disabled":false,"required":true,"hideLabel":false,"i18nCode":"fields_7792422","labelWidth":110,"offset":1,"accept":""},"fields_7274050":{"type":"title","controlType":"title","label":"文本","value":"上传指南","display":true,"span":22,"hideLabel":true,"styles":{},"i18nCode":"fields_7274050","offset":1},"fields_8886724":{"type":"title","controlType":"title","label":"文本","value":"请确保上传的资料符合公司保密规定，不包含敏感信息。","display":true,"span":22,"hideLabel":true,"styles":{},"i18nCode":"fields_8886724","offset":1,"stylesStr":"","className":"","moreOptionStr":""},"fields_7206180":{"type":"title","controlType":"title","label":"文本","value":"选择正确的制度分类有助于资料的组织和后续查找。","display":true,"span":22,"hideLabel":true,"styles":{},"i18nCode":"fields_7206180","offset":1},"fields_5409338":{"type":"title","controlType":"title","label":"文本","value":"资料名称应简洁明了，准确反映文件内容；描述应包含关键信息，便于他人快速了解资料用途。","display":true,"span":22,"hideLabel":true,"styles":{},"i18nCode":"fields_5409338","offset":1}},"display":true,"span":24,"hideLabel":false,"prop":"fields_4328084","i18nCode":"fields_4328084"}]}', 1814565091165110274, 'Y', 'N', 'N', '{"fields_867779":"return {\n  //简体中文\n  ''zh-CN'': ''资料名称'',\n  //English\n  ''en'': '''',\n}","fields_1781150":"return {\n  //简体中文\n  ''zh-CN'': ''所属部门'',\n  //English\n  ''en'': '''',\n}","fields_6672274":"return {\n  //简体中文\n  ''zh-CN'': ''资料分类'',\n  //English\n  ''en'': '''',\n}","fields_280965":"return {\n  //简体中文\n  ''zh-CN'': ''可见部门'',\n  //English\n  ''en'': '''',\n}","fields_3533958":"return {\n  //简体中文\n  ''zh-CN'': ''资料内容描述'',\n  //English\n  ''en'': '''',\n}","fields_5109620":"return {\n  //简体中文\n  ''zh-CN'': ''基本信息'',\n  //English\n  ''en'': '''',\n}","fields_7792422":"return {\n  //简体中文\n  ''zh-CN'': ''选择文件'',\n  //English\n  ''en'': '''',\n}","fields_4328084":"return {\n  //简体中文\n  ''zh-CN'': ''上传资料'',\n  //English\n  ''en'': '''',\n}","config_submitBtn":"return {\n  //简体中文\n  ''zh-CN'': ''提交'',\n  //English\n  ''en'': '''',\n}","config_emptyBtn":"return {\n  //简体中文\n  ''zh-CN'': ''清空'',\n  //English\n  ''en'': '''',\n}","config_externalTitle":"return {\n  //简体中文\n  ''zh-CN'': '''',\n  //English\n  ''en'': '''',\n}"}');