@jx3box/jx3box-vue3-ui 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jx3box/jx3box-vue3-ui",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "JX3BOX Vue3 UI",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,155 @@
1
+ <template>
2
+ <div class="c-upload-banner">
3
+ <el-alert class="u-tip" :title="info" v-if="info" type="info" show-icon></el-alert>
4
+ <div v-if="data" class="u-upload" :style="uploadStyle">
5
+ <img :src="preview" />
6
+ <i class="u-upload-mask"></i>
7
+ <el-icon class="u-upload-delete el-icon-delete" title="移除" @click="remove"><Delete /></el-icon>
8
+ </div>
9
+ <div v-else class="u-upload el-upload el-upload--picture-card" @click="select">
10
+ <el-icon><Plus /></el-icon>
11
+ </div>
12
+ <input
13
+ class="u-upload-input"
14
+ type="file"
15
+ @change="upload"
16
+ ref="uploadInput"
17
+ accept=".jpg, .jpeg, .png, .gif, .bmp,.webp"
18
+ />
19
+ </div>
20
+ </template>
21
+
22
+ <script>
23
+ import { getThumbnail } from "@jx3box/jx3box-common/js/utils";
24
+ import { upload } from "@/service/cms.js";
25
+ export default {
26
+ name: "upload-banner",
27
+ props: {
28
+ content: {
29
+ type: String,
30
+ default: "",
31
+ },
32
+ info: {
33
+ type: String,
34
+ // 用于展示tips
35
+ default: "",
36
+ },
37
+ size: {
38
+ type: [Array, Number],
39
+ default: 148,
40
+ },
41
+ maxSize: {
42
+ type: Number,
43
+ default: 10,
44
+ },
45
+ },
46
+ data() {
47
+ return {
48
+ data: this.content || "",
49
+ };
50
+ },
51
+ model: {
52
+ prop: "content",
53
+ event: "input",
54
+ },
55
+ watch: {
56
+ content(val) {
57
+ this.data = val;
58
+ },
59
+ data(val) {
60
+ this.$emit("input", val);
61
+ },
62
+ },
63
+ computed: {
64
+ fileInput: function () {
65
+ return this.$refs.uploadInput;
66
+ },
67
+ preview() {
68
+ let size = Array.isArray(this.size) ? this.size : [this.size, this.size];
69
+ return getThumbnail(this.data, size, true);
70
+ },
71
+ uploadStyle() {
72
+ let size = Array.isArray(this.size) ? this.size : [this.size, this.size];
73
+ return {
74
+ width: size[0] + "px",
75
+ height: size[1] + "px",
76
+ };
77
+ },
78
+ },
79
+ methods: {
80
+ select() {
81
+ this.fileInput.dispatchEvent(
82
+ new MouseEvent("click", {
83
+ bubbles: true,
84
+ cancelable: true,
85
+ view: window,
86
+ })
87
+ );
88
+ },
89
+ upload() {
90
+ const file = this.fileInput.files[0];
91
+ if (!file) return;
92
+ if (file.size > this.maxSize * 1024 * 1024) {
93
+ this.$message.error("图片大小不能超过" + this.maxSize + "M");
94
+ return;
95
+ }
96
+ const formData = new FormData();
97
+ formData.append("file", file);
98
+ upload(formData).then((res) => {
99
+ this.data = res.data.data[0];
100
+ this.$message({
101
+ message: "上传成功",
102
+ type: "success",
103
+ });
104
+ });
105
+ },
106
+ remove() {
107
+ this.data = "";
108
+ },
109
+ },
110
+ };
111
+ </script>
112
+
113
+ <style lang="less">
114
+ .c-upload-banner {
115
+ .u-tip {
116
+ padding: 5px 15px;
117
+ }
118
+ .u-upload {
119
+ .pr;
120
+ .size(148px);
121
+ .mt(10px);
122
+ img {
123
+ .size(100%);
124
+ .y(bottom);
125
+ }
126
+ .u-upload-mask {
127
+ .none;
128
+ .pa;
129
+ .lt(0);
130
+ .size(100%);
131
+ background-color: rgba(0, 0, 0, 0.6);
132
+ }
133
+ .u-upload-delete {
134
+ .pa;
135
+ .lt(50%);
136
+ .size(24px);
137
+ .fz(24px);
138
+ padding: 40px;
139
+ transform: translate(-50%, -50%);
140
+ color: #fff;
141
+ .pointer;
142
+ .none;
143
+ }
144
+ &:hover {
145
+ .u-upload-mask,
146
+ .u-upload-delete {
147
+ .db;
148
+ }
149
+ }
150
+ }
151
+ .u-upload-input {
152
+ .none;
153
+ }
154
+ }
155
+ </style>