@jx3box/jx3box-common-ui 5.7.3 → 5.7.6

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-common-ui",
3
- "version": "5.7.3",
3
+ "version": "5.7.6",
4
4
  "description": "JX3BOX UI",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/service/cms.js CHANGED
@@ -4,4 +4,8 @@ function getPostAuthors(post_id) {
4
4
  return $cms({mute:true}).get(`/api/cms/post/${post_id}/authors`);
5
5
  }
6
6
 
7
- export { getPostAuthors };
7
+ function uploadImage(formData){
8
+ return $cms().post(`/api/cms/upload/avatar`, formData);
9
+ }
10
+
11
+ export { getPostAuthors, uploadImage };
package/src/App.vue CHANGED
@@ -62,6 +62,9 @@
62
62
  <tagBy :data="['PVE', 'PVX']" :type="tag" />
63
63
  <clientBy type="" />
64
64
  <zlpBy />
65
+
66
+ <hr />
67
+ <uploadImage v-model="upload" info="非必选。首页海报尺寸1100*300(推荐2200*600支持高分屏),最大20M。"></uploadImage>
65
68
  </el-tab-pane>
66
69
  <el-tab-pane label="百科组件" name="wiki"
67
70
  ><WikiPanel :wiki-post="wikiPost">
@@ -142,6 +145,8 @@ import tagBy from "./filters/tagBy.vue";
142
145
  import clientBy from "./filters/clientBy.vue";
143
146
  import zlpBy from "./filters/zlpBy.vue";
144
147
 
148
+ import uploadImage from './upload/upload_banner.vue'
149
+
145
150
  import WikiPanel from "./wiki/WikiPanel.vue";
146
151
  import WikiRevisions from "./wiki/WikiRevisions.vue";
147
152
  import WikiComments from "./wiki/WikiComments.vue";
@@ -193,6 +198,8 @@ export default {
193
198
  clientBy,
194
199
  zlpBy,
195
200
 
201
+ uploadImage,
202
+
196
203
  WikiPanel,
197
204
  WikiRevisions,
198
205
  WikiComments,
@@ -212,6 +219,8 @@ export default {
212
219
  visible: false,
213
220
 
214
221
  avatar_size : 60,
222
+
223
+ upload: '',
215
224
  };
216
225
  },
217
226
  created: function() {
@@ -0,0 +1,154 @@
1
+ <template>
2
+ <div class="c-upload-banner">
3
+ <el-alert class="u-tip" :title="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
+ <i class="u-upload-delete el-icon-delete" title="移除" @click="remove"></i>
8
+ </div>
9
+ <div v-else class="u-upload el-upload el-upload--picture-card" @click="select">
10
+ <i class="el-icon-plus"></i>
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 { uploadImage } 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
+ default: "用于展示tips",
35
+ },
36
+ size: {
37
+ type: [Array, Number],
38
+ default: 148,
39
+ },
40
+ maxSize: {
41
+ type: Number,
42
+ default: 10,
43
+ },
44
+ },
45
+ data() {
46
+ return {
47
+ data: this.content || "",
48
+ };
49
+ },
50
+ model: {
51
+ prop: "content",
52
+ event: "input",
53
+ },
54
+ watch: {
55
+ content(val) {
56
+ this.data = val;
57
+ },
58
+ data(val) {
59
+ this.$emit("input", val);
60
+ },
61
+ },
62
+ computed: {
63
+ fileInput: function () {
64
+ return this.$refs.uploadInput;
65
+ },
66
+ preview() {
67
+ let size = Array.isArray(this.size) ? this.size : [this.size, this.size];
68
+ return getThumbnail(this.data, size, true);
69
+ },
70
+ uploadStyle() {
71
+ let size = Array.isArray(this.size) ? this.size : [this.size, this.size];
72
+ return {
73
+ width: size[0] + "px",
74
+ height: size[1] + "px",
75
+ };
76
+ },
77
+ },
78
+ methods: {
79
+ select() {
80
+ this.fileInput.dispatchEvent(
81
+ new MouseEvent("click", {
82
+ bubbles: true,
83
+ cancelable: true,
84
+ view: window,
85
+ })
86
+ );
87
+ },
88
+ upload() {
89
+ const file = this.fileInput.files[0];
90
+ if (!file) return;
91
+ if (file.size > this.maxSize * 1024 * 1024) {
92
+ this.$message.error("图片大小不能超过" + this.maxSize + "M");
93
+ return;
94
+ }
95
+ const formData = new FormData();
96
+ formData.append("avatar", file);
97
+ uploadImage(formData).then((res) => {
98
+ this.data = res.data.data[0];
99
+ this.$message({
100
+ message: "上传成功",
101
+ type: "success",
102
+ });
103
+ });
104
+ },
105
+ remove() {
106
+ this.data = "";
107
+ },
108
+ },
109
+ };
110
+ </script>
111
+
112
+ <style lang="less">
113
+ .c-upload-banner {
114
+ .u-tip {
115
+ padding: 5px 15px;
116
+ }
117
+ .u-upload {
118
+ .pr;
119
+ .size(148px);
120
+ .mt(10px);
121
+ img {
122
+ .size(100%);
123
+ .y(bottom);
124
+ }
125
+ .u-upload-mask {
126
+ .none;
127
+ .pa;
128
+ .lt(0);
129
+ .size(100%);
130
+ background-color: rgba(0, 0, 0, 0.6);
131
+ }
132
+ .u-upload-delete {
133
+ .pa;
134
+ .lt(50%);
135
+ .size(24px);
136
+ .fz(24px);
137
+ padding: 40px;
138
+ transform: translate(-50%, -50%);
139
+ color: #fff;
140
+ .pointer;
141
+ .none;
142
+ }
143
+ &:hover {
144
+ .u-upload-mask,
145
+ .u-upload-delete {
146
+ .db;
147
+ }
148
+ }
149
+ }
150
+ .u-upload-input {
151
+ .none;
152
+ }
153
+ }
154
+ </style>