Show newer

封装了一个element ui多图上传组件,支持v-model

<template>
  <div
    class="uploader"
    :exceed="
      $props.value.length >= $props.limit ||
        (pending && $props.value.length === $props.limit - 1)
    "
  >
    <el-upload
      action=""
      list-type="picture-card"
      :on-success="handleOnUploadSuccess"
      :on-error="handleOnUploadError"
      :on-exceed="handleOnUploadExceed"
      :on-remove="handleOnRemove"
      :before-upload="handleBeforeUpload"
      :http-request="handleUploadHttpRequest"
      :file-list="$props.value"
      :on-preview="handlePreview"
      :show-file-list="true"
      :limit="$props.limit"
      accept="image/png,image/gif,image/jpg,image/jpeg"
    >
      <i class="el-icon-plus"></i>
    </el-upload>
    <ElImageViewer
      v-if="showViewer"
      :on-close="() => (showViewer = false)"
      :url-list="[viewerUrl]"
    ></ElImageViewer>
  </div>
</template>

<script>
import ElImageViewer from "element-ui/packages/image/src/image-viewer";
export default {
  components: { ElImageViewer },
  props: {
    value: { type: Array, default: () => [] },
    api: Function,
    fileName: { type: String, default: "file" },
    limit: { type: Number, default: 3 },
    size: { type: Number, default: 5 }
  },
  model: {
    prop: "value",
    event: "change"
  },
  data() {
    return {
      pending: false,
      viewerUrl: "",
      showViewer: false,
      attachmentFetching: true,
      attachmentUploading: false,
      attachmentTooLarge: false,
      attachmentUploadFormData: new FormData()
    };
  },
  methods: {
    handleOnUploadSuccess(response, file, fileList) {
      this.attachmentUploadFormData.delete(this.$props.fileName);
      this.attachmentUploading = false;
      this.$message.success("上传成功");
      fileList[fileList.length - 1].url = response.data;
      fileList[fileList.length - 1].isDefault = 1;
      this.$emit("change", fileList);
      this.pending = false;
    },
    handleOnUploadError(error) {
      this.attachmentUploadFormData.delete(this.$props.fileName);
      this.attachmentUploading = false;
      this.$message.error(error.msg || error);
      this.pending = false;
    },
    handleBeforeUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < this.$props.size;
      if (!isLt2M) {
        this.attachmentTooLarge = true;
        this.$message.error(`上传图片大小不能超过 ${this.$props.size}MB!`);
        return false;
      }
      this.attachmentUploadFormData.append(this.$props.fileName, file);
      this.pending = true;
      return true;
    },
    handleOnUploadExceed() {
      this.$message.error(`最多只能上传 ${this.$props.limit} 个附件~`);
    },
    async handleUploadHttpRequest() {
      this.attachmentUploading = true;
      return this.$props
        .api(this.attachmentUploadFormData)
        .then(response => Promise.resolve(response))
        .catch(error => Promise.reject(error));
    },
    handlePreview(file) {
      this.viewerUrl = file.url;
      this.showViewer = true;
    },
    handleOnRemove(file, fileList) {
      if (this.attachmentTooLarge) {
        this.attachmentTooLarge = false;
        return;
      }
      this.$emit("change", fileList);
    }
  }
};
</script>

<style lang="scss" scoped>
.uploader {
  display: inline-block;
  width: 100%;
  &[exceed="true"] {
    ::v-deep {
      .el-upload.el-upload--picture-card {
        display: none;
      }
    }
  }
  ::v-deep {
    .el-list-enter-active,
    .el-list-leave-active {
      transition: unset;
    }
    .el-list-enter,
    .el-list-leave-active {
      opacity: 0;
      transform: unset;
    }
  }
}
</style>

苹果教intel造CPU,教NVIDA造GPU系列 :bili_tv_xiaoku:
似乎PRO和MAX的区别就只是GPU?

王小美 boosted

苹果 M1 pro 的显卡性能,据说达到了 RTX 3050Ti 的水平。这是不是说,苹果的游戏短板终于补起了,以后可以在 MacBook Pro 玩大型游戏了。
anandtech.com/show/17019/apple

:sys_twitter: twitter.com/ruanyf/status/1450

突然觉得我是不是有点水PR的嫌疑 :ac_classic05:

github.com/go-gitea/gitea/pull

改天得正儿八经地给它提交点代码,反正移动端适配想提交多少有多少 :ac_classic24:

Mastodon终于解决了kt-paperclip的compatible S3兼容问题
github.com/mastodon/mastodon/p

PS. 前天给kt-paperclip提issue,发现其实这个分支提交也没多少,issue基本没人回复啊。似乎是几个印度人在维护 😪

list users @note

awk -F: '/\/home/ {printf "%s:%s\n",$1,$3}' /etc/passwd

分享动态
//转发自: @KKOMDA: 【原神1周年】感谢你们出现在我的生命中!
感谢大家对我视频的支持和喜爱!~
一路走来有你们的陪伴真的非常开心!也感谢原神这款游戏给我带来的快乐!
原神一周年生日快乐!

:sys_video: api.2heng.xin/bilibili/og.php?
:sys_bilibili: t.bilibili.com/582573001874250

王小美 boosted

华卡雷瓦雷瓦森林的红木纪念树林,新西兰北岛 (© Michael Breitung/Huber/eStock Photo)

王小美 boosted
王小美 boosted

꒰⑅•ᴗ•⑅꒱走进秘密的小森林,和2233一起开橘红色的派对吧!

白天效果 06:00am——16:00pm;
傍晚效果 16:00pm——19:00pm;
夜晚效果 19:00pm——06:00am;

:sys_video: api.2heng.xin/bilibili/og.php?
:sys_bilibili: t.bilibili.com/581775104319158

Show older
小森林

每个人都有属于自己的一片森林,也许我们从来不曾走过,但它一直在那里,总会在那里。迷失的人迷失了,相逢的人会再相逢。愿这里,成为属于你的小森林。