张诺
15 小时以前 df982f1554a029a57b0b21ecaa740233cab09a9d
src/components/ImageUpload/index.vue
@@ -112,10 +112,15 @@
      // 然后将数组转为对象数组
      fileList.value = list.map((item) => {
        if (typeof item === "string") {
          if (item.indexOf(baseUrl) === -1 && !isExternal(item)) {
            item = { name: baseUrl + item, url: baseUrl + item };
          const url =
            item.indexOf(baseUrl) === -1 && !isExternal(item)
              ? baseUrl + item
              : item;
          item = { name: getFileName(url), url };
          } else {
            item = { name: item, url: item };
          item = { ...item };
          if (!item.name) {
            item.name = getFileName(item.url || item.name || "");
          }
        }
        return item;
@@ -189,7 +194,7 @@
  const findex = fileList.value.map((f) => f.name).indexOf(file.name);
  if (findex > -1 && uploadList.value.length === number.value) {
    fileList.value.splice(findex, 1);
    emit("update:modelValue", listToString(fileList.value));
    emit("update:modelValue", fileList.value);
    return false;
  }
}
@@ -202,7 +207,7 @@
      .concat(uploadList.value);
    uploadList.value = [];
    number.value = 0;
    emit("update:modelValue", listToString(fileList.value));
    emit("update:modelValue", fileList.value);
    proxy.$modal.closeLoading();
  }
}
@@ -219,16 +224,13 @@
  dialogVisible.value = true;
}
// 对象转成指定字符串分隔
function listToString(list, separator) {
  let strs = "";
  separator = separator || ",";
  for (let i in list) {
    if (undefined !== list[i].url && list[i].url.indexOf("blob:") !== 0) {
      strs += list[i].url.replace(baseUrl, "") + separator;
// 获取文件名
function getFileName(name) {
  if (!name) return "";
  if (name.lastIndexOf("/") > -1) {
    return name.slice(name.lastIndexOf("/") + 1);
    }
  }
  return strs != "" ? strs.substr(0, strs.length - 1) : "";
  return name;
}
// 初始化拖拽排序