QB fast 下载模板 报错

发布于:2024-04-20 ⋅ 阅读:(19) ⋅ 点赞:(0)

 useExportAndImoort.tsx 

  const importTemplate = () => {
    const headers = addColumns;
    let len = 0;
    const headersTmp = headers
      .map((item, i) => {
        const obj: any = {
          key: item.field,
          title: item.label,
          position: getPosition(i) + 1,
        };
        if (item.list) {
          const c: XLSX.Comments = [];
          c.hidden = true;
          c.push({ a: 'QBFast', t: `值只能为:${item.list.map((item) => item.label).join(',')}` });
          len = Math.max(len, item.list.length);
          obj.c = c;
        }
        return obj;
      })
      .reduce((prev, next) => {
        const obj: any = { ...prev, [next.position]: { key: next.key, v: next.title } };
        if (next.c) {
          obj[next.position].c = next.c;
        }
        return obj;
      }, {});
    const data = [];
    for (let i = 0; i < len; i++) {
      const form = {};
      headers.forEach((item) => {
        form[item.field] = '';

         //  原本的   
        // if (item.list) {
        //   form[item.field] = (item.list[i] && item.list[i].value) || item.list[0].value;
        // }
        //修改过后的
        if (item.list && item.list.length > i) {
          form[item.field] = item.list[i] && item.list[i].value !== undefined ? item.list[i].value : item.list[0].value;
        }
      });
      data.push(form);
    }
    let dataTmp: any = [];
    if (data.length > 0) {
      dataTmp = data
        .map((item, i) =>
          headers.map((key, j) => {
            return {
              content: item[key.field],
              position: getPosition(j) + (i + 2),
            };
          }),
        )
        // 对刚才的结果进行降维处理(二维数组变成一维数组)
        .reduce((prev, next) => prev.concat(next))
        // 转换成 worksheet 需要的结构
        .reduce((prev, next) => ({ ...prev, [next.position]: { v: next.content } }), {});
    }

    // 合并 headers 和 data
    const output = { ...headersTmp, ...dataTmp };
    // 获取所有单元格的位置
    const outputPos = Object.keys(output);
    // 计算出范围 ,["A1",..., "H2"]
    const ref = `${outputPos[0]}:${outputPos[outputPos.length - 1]}`;
    // 构建 workbook 对象
    const wb = {
      SheetNames: [name],
      Sheets: {},
    };
    wb.Sheets[name] = {
      ...output,
      '!ref': ref,
      '!cols': headers.map(() => ({ wpx: 100 })),
    };
    // 导出 Excel
    XLSX.writeFile(wb, `${name}-模板.xlsx`);
  };

QB fast  拉下来代码 不能web 后台 点击不能直接跳转 必须的 刷新的解决办法:

 

  setup() {
    const crumbs = computed(() => {
      const route = useRoute();
        // 新增
      if (!route) return [];

      const pathArray = route.path.split('/');
      pathArray.shift();

      const breadcrumbs = pathArray.reduce((breadcrumbArray, path, idx) => {
        breadcrumbArray.push({
          path,
          to: breadcrumbArray[idx - 1] ? `/${breadcrumbArray[idx - 1].path}/${path}` : `/${path}`,
          title: route.matched[idx].meta.title || path,
        });
        return breadcrumbArray;
      }, []);
      return breadcrumbs;
    });

    return {
      crumbs,
    };
  },

 

 

 

  setup(props) {
    const store = useStore();
    const router = useRouter();

    const toggleSettingPanel = () => {
      store.commit('setting/toggleSettingPanel', true);
    };

    const active = computed(() => {
      const route = useRoute();

    //修改 
      if (route && route?.path) {
        return route.path
          .split('/')
          .filter((item, index) => index <= props.maxLevel && index > 0)
          .map((item) => `/${item}`)
          .join('');
      }
      return '';
    });

    const showMenu = computed(() => !(props.layout === 'mix' && props.showLogo));

    const layoutCls = computed(() => [`${prefix}-header-layout`]);

    const menuCls = computed(() => {
      const { isFixed, layout, isCompact } = props;
      return [
        {
          [`${prefix}-header-menu`]: !isFixed,
          [`${prefix}-header-menu-fixed`]: isFixed,
          [`${prefix}-header-menu-fixed-side`]: layout === 'side' && isFixed,
          [`${prefix}-header-menu-fixed-side-compact`]: layout === 'side' && isFixed && isCompact,
        },
      ];
    });

    const userVisible = ref(false);
    const userVisibleChange = (value: boolean) => {
      userVisible.value = value;
    };

    const changeCollapsed = () => {
      store.commit('setting/toggleSidebarCompact');
    };
    const isSidebarCompact = computed(() => store.state.setting.isSidebarCompact);

    const handleNav = (url) => {
      router.push(url);
    };
    const loginDropdown = ref(null);
    const handleLogout = () => {
      // loginDropdown.value.$refs.popupElem.handleClose();
      const dialog = confirm({
        body: '您确定要退出登录吗?',
        onConfirm: () => {
          router.replace(`/login?redirect=${router.currentRoute.value.fullPath}`);
          dialog.hide();
        },
      });
    };

    const progress = reactive({
      visible: false,
      percentage: 0,
    });

    const showBreadcrumb = computed(() => {
      return store.state.setting.showBreadcrumb;
    });

    return {
      progress,
      isSidebarCompact,
      toggleSettingPanel,
      active,
      showMenu,
      layoutCls,
      userVisible,
      userVisibleChange,
      menuCls,
      changeCollapsed,
      handleNav,
      handleLogout,
      loginDropdown,
      showBreadcrumb,
      username: computed(() => store.getters['user/user']('name')),
      toLock: () => {
        const dialog = confirm({
          body: '您确定要锁屏吗?',
          onConfirm: () => {
            store.dispatch('lockscreen/setLockTime', 0);
            dialog.hide();
          },
        });
      },
    };
  },

 

 

  {scenes.import || scenes.export
                    ? useExportAndImport(api.title, api.api, taoTable, scenes.import ? (props.importTemplate.length>0?props.importTemplate:addColumns) : [])
                    : ''}
                  {scenes.add ? (
                    <t-button theme="primary" onClick={() => editForm()}>
                      {{
                        default: () => '新增',
                        icon: () => <t-icon name="add" />,
                      }}
                    </t-button>
                  ) : (
                    ''
                  )}
                </>
              );
            },

 


网站公告

今日签到

点亮在社区的每一天
去签到