餐饮油烟智能监测与监管一体化平台
riku
2026-03-18 8e8d00477b1f30183d0d09cd7ec744067595dc46
src/api/fytz/creditApi.js
@@ -1,27 +1,35 @@
import { Base64 } from 'js-base64';
import { $fytz } from '../index';
import { Base64 } from 'js-base64'
import { $fytz } from '../index'
/**
 * 信用评估API接口
 */
export default {
  /**
   * 下载用户环信码
   * @param {*} userId
   */
  downloadCode(userId) {
  fetchCodeUrl(userId, userName) {
    return $fytz
      .get(`credit/ecCode/download?userId=${userId}`, { responseType: 'blob' })
      .then((res) => {
        const name = Base64.decode(res.headers.get('fileName'));
        const url = window.URL.createObjectURL(res.data);
        const link = document.createElement('a');
        link.href = url;
        link.setAttribute('download', name);
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        window.URL.revokeObjectURL(url);
      });
  }
};
        const name = res.headers.get('fileName') || userName
        const fileName = Base64.decode(name)
        const url = window.URL.createObjectURL(res.data)
        return { fileName, url }
      })
  },
  /**
   * 下载用户环信码
   * @param {*} userId
   * @param {*} userName
   */
  downloadCode(userId, userName) {
    return this.fetchCodeUrl(userId, userName).then((res) => {
      const { fileName, url } = res
      const link = document.createElement('a')
      link.href = url
      link.setAttribute('download', fileName)
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
      window.URL.revokeObjectURL(url)
    })
  },
}