index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import Vue from 'vue'
  2. Vue.mixin({
  3. components: {
  4. },
  5. data() {
  6. return {
  7. $__loading:{
  8. close(){
  9. }
  10. },
  11. loadOption:{
  12. lock: true,
  13. text: '上傳中',
  14. spinner: 'el-icon-loading',
  15. background: 'rgba(0, 0, 0, 0.7)'
  16. }
  17. }
  18. },
  19. methods: {
  20. $beforeUpload(file) {
  21. let type = this.isImage(file.name);
  22. if (!type) {
  23. this.$message.error("只允許上傳圖片");
  24. return type;
  25. }
  26. const isLt2M = file.size / 1024 / 1024 < 5;
  27. if (!isLt2M) {
  28. this.$message.error("上傳圖片大小不能超過 5MB!");
  29. return isLt2M;
  30. }
  31. this.showLoading()
  32. },
  33. handleError(){
  34. this.$alert("上傳失敗,請稍後再試", "提示", {
  35. confirmButtonText: "確定",
  36. callback: () => {
  37. this.$__loading.close()
  38. },
  39. });
  40. },
  41. showLoading(){
  42. this.$__loading = this.$loading(this.loadOption)
  43. },
  44. $inputnum(e){
  45. console.log('e',e)
  46. e = (e.match(/^\d*(\.?\d{0,2})/g)[0]) || null
  47. }
  48. }
  49. })