vporto.js 864 Bytes
import Vue from "vue";
/**
 * 图片上传限制
 */
Vue.prototype.uploadImgCondition = function(file) {
  const isJPG = file.type === "image/jpeg";
  const isLt2M = file.size / 1024 / 1024 < 2;

  if (!isJPG) {
    this.$message.error("上传头像图片只能是 JPG 格式!");
  }
  if (!isLt2M) {
    this.$message.error("上传头像图片大小不能超过 2MB!");
  }
  return isJPG && isLt2M;
};

/**
 * tar文件上传设置
 */
Vue.prototype.uploadFile = function(file, type, size) {
  const isType = file.raw.type === type;
  let isSize = true;
  if (size) {
    isSize = file.size / 1024 / 1024 < size;
  }

  if (!isType) {
    this.$message.error(`上传头像文件只能${type}是格式!`);
  }
  if (size && !isSize) {
    this.$message.error(`文件大小不能超过 ${size}MB!`);
  }
  return isType && isSize;
};
Vue.prototype.globalWs = null;