shijiplus-web-plugin 0.1.34 → 0.1.36

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.
@@ -0,0 +1,222 @@
1
+ <template>
2
+ <div>
3
+ <div
4
+ class="demo-upload-list"
5
+ :key="item.id"
6
+ v-show="item.type == showType"
7
+ v-for="(item, index) in uploadList"
8
+ >
9
+ <img v-show="item.type == 'pdf'" src="@/assets/images/pdf.jpeg" />
10
+ <img v-show="item.type == 'word'" src="@/assets/images/word.jpeg" />
11
+ <div class="demo-upload-list-cover">
12
+ <Icon
13
+ v-if="!disabled"
14
+ type="ios-trash-outline"
15
+ @click.native="handleRemove(item, index)"
16
+ ></Icon>
17
+ </div>
18
+ </div>
19
+ <Upload
20
+ ref="upload"
21
+ :show-upload-list="false"
22
+ :default-file-list="defaultFiles"
23
+ :on-success="handleSuccess"
24
+ :format="['pdf', 'docx', 'doc']"
25
+ :headers="headers"
26
+ :max-size="fileMaxSize"
27
+ :on-format-error="handleFormatError"
28
+ :on-exceeded-size="handleMaxSize"
29
+ multiple
30
+ type="drag"
31
+ :before-upload="handleBeforeUpload"
32
+ :action="action || baseUrl + 'api/open/common/file/uploadFile'"
33
+ :class="{ hideUpload: remainderCount <= 0 }"
34
+ style="display: inline-block; width: 58px"
35
+ >
36
+ <div style="width: 58px; height: 58px; line-height: 58px">
37
+ <Icon :type="addIconType" size="20"></Icon>
38
+ </div>
39
+ </Upload>
40
+ </div>
41
+ </template>
42
+ <script>
43
+ import config from '@/config'
44
+ import store from '@/store'
45
+ const baseUrl = config.plusApiV5Domain()
46
+ let authHeader = {}
47
+ authHeader[config.tokenHeaderName] = store.state.user.token
48
+ authHeader['token'] = store.state.user.token
49
+ authHeader['app_name'] = 'op'
50
+ export default {
51
+ name: 'upload-file',
52
+ props: {
53
+ disabled: {
54
+ default: false
55
+ },
56
+ hintText: {
57
+ type: String,
58
+ default: ''
59
+ },
60
+ filePath: {
61
+ default: undefined
62
+ },
63
+ addIconType: {
64
+ default: 'md-cloud-upload'
65
+ },
66
+ maxUploadFiles: {
67
+ default: 1
68
+ },
69
+ maxSize: {
70
+ default: 20480
71
+ },
72
+ action: {
73
+ default: ''
74
+ },
75
+ fileName: {
76
+ de3fault: ''
77
+ }
78
+ },
79
+ data() {
80
+ return {
81
+ headers: authHeader,
82
+ baseUrl,
83
+ remainderCount: this.maxUploadFiles,
84
+ uploadList: [
85
+ {
86
+ type: 'pdf',
87
+ url: '@/assets/images/pdf.jpeg'
88
+ },
89
+ {
90
+ type: 'word',
91
+ url: '@/assets/images/word.jpeg'
92
+ }
93
+ ],
94
+ showType: '',
95
+ localFileName: '',
96
+ defaultFiles: [],
97
+ fileMaxSize: this.maxSize
98
+ }
99
+ },
100
+ watch: {
101
+ filePath(value) {
102
+ this.showType = ''
103
+ this.$refs.upload.clearFiles()
104
+ this.remainderCount = this.maxUploadFiles
105
+ if (!this.$isEmpty(value)) {
106
+ this.showType =
107
+ value.slice(value.indexOf('.') + 1) == 'pdf' ? 'pdf' : 'word'
108
+ this.defaultFiles = []
109
+ this.remainderCount -= 1
110
+ }
111
+ },
112
+
113
+ fileName(value) {
114
+ this.localFileName = value
115
+ }
116
+ },
117
+ methods: {
118
+ handleRemove(file, index) {
119
+ this.showType = ''
120
+ this.remainderCount++
121
+ if (
122
+ !this.$isEmpty(this._events) &&
123
+ typeof this._events['on-remove'] === 'object'
124
+ ) {
125
+ this.$emit('on-remove', { index: index, target: this })
126
+ } else {
127
+ if (
128
+ this.maxUploadFiles === 1 &&
129
+ this.$containKey(this.$options.propsData, 'imagePath')
130
+ ) {
131
+ this.$emit('on-remove', { index: index, target: this })
132
+ }
133
+ }
134
+ },
135
+ handleSuccess(res, file) {
136
+ this.remainderCount--
137
+ file.url = res.data.path
138
+ file.name = res.data.path
139
+ res.data.fileName = this.localFileName
140
+ this.showType =
141
+ res.data.path.slice(res.data.path.indexOf('.') + 1) == 'pdf'
142
+ ? 'pdf'
143
+ : 'word'
144
+ if (
145
+ !this.$isEmpty(this._events) &&
146
+ typeof this._events['on-upload-complete'] === 'object'
147
+ ) {
148
+ this.$emit('on-upload-complete', { res: res, file: file, target: this })
149
+ } else {
150
+ if (this.maxUploadFiles === 1) {
151
+ if (this.$containKey(this.$options.propsData, 'imagePath')) {
152
+ this.$emit('on-upload-complete', {
153
+ res: res,
154
+ file: file,
155
+ target: this
156
+ })
157
+ }
158
+ }
159
+ }
160
+ },
161
+ handleFormatError(file) {
162
+ this.remainderCount++
163
+ this.$Notice.warning({
164
+ title: '文件格式错误',
165
+ desc: '只能上传 word 或 pdf格式的 文件.'
166
+ })
167
+ },
168
+ handleMaxSize(file) {
169
+ this.remainderCount++
170
+ this.$Notice.warning({
171
+ title: '文件超过20M',
172
+ desc: `文件不能大于20M`
173
+ })
174
+ },
175
+ handleBeforeUpload(data) {
176
+ this.localFileName = data.name
177
+ }
178
+ },
179
+ mounted() {}
180
+ }
181
+ </script>
182
+ <style>
183
+ .hideUpload {
184
+ display: none !important;
185
+ }
186
+ .demo-upload-list {
187
+ display: inline-block;
188
+ width: 60px;
189
+ height: 60px;
190
+ text-align: center;
191
+ line-height: 60px;
192
+ border: 1px solid transparent;
193
+ border-radius: 4px;
194
+ overflow: hidden;
195
+ background: #fff;
196
+ position: relative;
197
+ box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
198
+ margin-right: 4px;
199
+ }
200
+ .demo-upload-list img {
201
+ width: 100%;
202
+ height: 100%;
203
+ }
204
+ .demo-upload-list-cover {
205
+ display: none;
206
+ position: absolute;
207
+ top: 0;
208
+ bottom: 0;
209
+ left: 0;
210
+ right: 0;
211
+ background: rgba(0, 0, 0, 0.6);
212
+ }
213
+ .demo-upload-list:hover .demo-upload-list-cover {
214
+ display: block;
215
+ }
216
+ .demo-upload-list-cover i {
217
+ color: #fff;
218
+ font-size: 20px;
219
+ cursor: pointer;
220
+ margin: 0 2px;
221
+ }
222
+ </style>
@@ -0,0 +1,203 @@
1
+ <template>
2
+ <div id="upload-input">
3
+ <Upload
4
+ ref="upload"
5
+ :show-upload-list="false"
6
+ :default-file-list="defaultFiles"
7
+ :on-success="handleSuccess"
8
+ :format="format"
9
+ :accept="accept"
10
+ :headers="headers"
11
+ :max-size="fileMaxSize"
12
+ :sizeUnit="sizeUnit"
13
+ :sizeUnitStr="sizeUnitStr"
14
+ :on-format-error="handleFormatError"
15
+ :on-exceeded-size="handleMaxSize"
16
+ :before-upload="handleBeforeUpload"
17
+ :multiple="maxUploadFiles > 1"
18
+ :action="baseUrl + 'api/open/common/file/uploadFile'"
19
+ >
20
+ <slot></slot>
21
+ </Upload>
22
+ </div>
23
+ </template>
24
+ <script>
25
+ import config from '@/config'
26
+ import store from '@/store'
27
+ const baseUrl = config.plusApiV5Domain()
28
+ let authHeader = {}
29
+ authHeader[config.tokenHeaderName] = store.state.user.token
30
+ authHeader['app_name'] = 'op'
31
+ export default {
32
+ name: 'UploadFileInput',
33
+ props: {
34
+ showImgList: {
35
+ default: () => {
36
+ return undefined
37
+ }
38
+ },
39
+ imagePath: {
40
+ default: undefined
41
+ },
42
+ addIconType: {
43
+ default: 'ios-camera'
44
+ },
45
+ accept: {
46
+ default: 'image/*'
47
+ },
48
+ format: {
49
+ default() {
50
+ return ['jpg', 'jpeg', 'png', 'gif']
51
+ }
52
+ },
53
+ maxUploadFiles: {
54
+ default: 1
55
+ },
56
+ maxSize: {
57
+ default: 2
58
+ },
59
+ sizeUnit: {
60
+ default: 1024
61
+ },
62
+ sizeUnitStr: {
63
+ default: 'MB'
64
+ }
65
+ },
66
+ data() {
67
+ return {
68
+ headers: authHeader,
69
+ baseUrl,
70
+ imgName: '',
71
+ visible: false,
72
+ remainderCount: this.maxUploadFiles,
73
+ uploadList: [],
74
+ defaultFiles: []
75
+ }
76
+ },
77
+ computed: {
78
+ fileMaxSize() {
79
+ return this.maxSize * this.sizeUnit
80
+ }
81
+ },
82
+ watch: {
83
+ imagePath(value) {
84
+ this.uploadList = []
85
+ this.$refs.upload.clearFiles()
86
+ this.remainderCount = this.maxUploadFiles
87
+ if (!this.$isEmpty(value)) {
88
+ if (!this.$isEmpty(this.uploadList)) {
89
+ this.uploadList.push({
90
+ name: value,
91
+ url: value,
92
+ status: 'finished'
93
+ })
94
+ } else {
95
+ this.uploadList = [{ name: value, url: value, status: 'finished' }]
96
+ }
97
+ this.defaultFiles = this.$deepCopy(this.uploadList)
98
+ this.remainderCount -= this.uploadList.length
99
+ }
100
+ },
101
+ showImgList(value) {
102
+ if (this.$refs.upload.fileList.length > 0) {
103
+ let uploadingImgs = this.$refs.upload.fileList.filter((item) => {
104
+ return item.status === 'uploading'
105
+ })
106
+ if (uploadingImgs.length > 0) {
107
+ return
108
+ }
109
+ }
110
+ this.remainderCount = this.maxUploadFiles
111
+ this.uploadList = []
112
+ if (!this.$isEmpty(value)) {
113
+ value.forEach((item, index) => {
114
+ this.uploadList.push({
115
+ name: item,
116
+ url: item,
117
+ status: 'finished'
118
+ })
119
+ })
120
+ }
121
+ this.defaultFiles = this.$deepCopy(this.uploadList)
122
+ this.remainderCount -= this.uploadList.length
123
+ }
124
+ },
125
+ methods: {
126
+ handleSuccess(res, file) {
127
+ const oriFile = this.$deepCopy(file)
128
+ file.url = res.data.path
129
+ file.name = res.data.path
130
+ file.status = 'finished'
131
+ this.uploadList = this.$refs.upload.fileList
132
+ if (
133
+ !this.$isEmpty(this._events) &&
134
+ typeof this._events['on-upload-complete'] === 'object'
135
+ ) {
136
+ this.$emit('on-upload-complete', {
137
+ res: res,
138
+ file: file,
139
+ target: this,
140
+ oriFile
141
+ })
142
+ } else {
143
+ if (this.maxUploadFiles === 1) {
144
+ if (this.$containKey(this.$options.propsData, 'imagePath')) {
145
+ this.$emit('on-upload-complete', {
146
+ res: res,
147
+ file: file,
148
+ target: this,
149
+ oriFile
150
+ })
151
+ } else {
152
+ if (this.showImgList) {
153
+ this.showImgList.splice(0, this.showImgList.length)
154
+ this.showImgList.push(res.data.path)
155
+ }
156
+ }
157
+ } else {
158
+ if (this.showImgList) {
159
+ this.showImgList.push(res.data.path)
160
+ }
161
+ }
162
+ }
163
+ },
164
+ handleFormatError(file) {
165
+ this.remainderCount++
166
+ this.$Notice.warning({
167
+ title: '文件格式错误',
168
+ desc: '只能上传 jpeg, jpg 或 png 文件.'
169
+ })
170
+ },
171
+ handleMaxSize(file) {
172
+ this.remainderCount++
173
+ this.$Notice.warning({
174
+ title: `文件超过${this.fileMaxSize / this.sizeUnit}${this.sizeUnitStr}`,
175
+ desc: `文件不能大于 ${this.fileMaxSize / this.sizeUnit}${
176
+ this.sizeUnitStr
177
+ }`
178
+ })
179
+ },
180
+ handleBeforeUpload() {
181
+ var check = true
182
+ // if (this.remainderCount <= 0) {
183
+ // this.$Notice.warning({
184
+ // title: `只能上传 ${this.maxUploadFiles} 张图片.`
185
+ // })
186
+ // check = false
187
+ // } else {
188
+ // this.remainderCount--
189
+ // }
190
+ return check
191
+ }
192
+ },
193
+ mounted() {}
194
+ }
195
+ </script>
196
+ <style lang="less" scoped>
197
+ #upload-input {
198
+ width: fit-content !important;
199
+ .ivu-upload {
200
+ width: fit-content !important;
201
+ }
202
+ }
203
+ </style>
@@ -0,0 +1,103 @@
1
+ <template>
2
+ <upload-file
3
+ @on-remove="handleRemove"
4
+ @on-upload-complete="handleSuccess"
5
+ :showImgList="fileList"
6
+ :maxUploadFiles="1"
7
+ :max-size="fileMaxSize"
8
+ :action="action"
9
+ :disabled="disabled"
10
+ :defaultHint="defaultHint"
11
+ :hintText="hintText"
12
+ :sizeUnit="sizeUnit"
13
+ :sizeUnitStr="sizeUnitStr"
14
+ :imgTitle="imgTitle"
15
+ >
16
+ <slot slot="tips" name="tips"></slot>
17
+ </upload-file>
18
+ </template>
19
+ <script>
20
+ import UploadFile from '_c/upload-file/upload-file'
21
+ export default {
22
+ name: 'upload-file-single',
23
+ components: { UploadFile },
24
+ model: {
25
+ prop: 'imgPath',
26
+ event: 'img-changed'
27
+ },
28
+ props: {
29
+ imgTitle: {
30
+ type: String,
31
+ default: '添加图片'
32
+ },
33
+ placeholder: {
34
+ type: String
35
+ },
36
+ disabled: {
37
+ type: Boolean,
38
+ default: false
39
+ },
40
+ defaultHint: {
41
+ type: Boolean
42
+ },
43
+ hintText: {
44
+ type: String
45
+ },
46
+ imgPath: {
47
+ default: ''
48
+ },
49
+ maxSize: {
50
+ default: 2048
51
+ },
52
+ sizeUnit: {
53
+ default: 1024
54
+ },
55
+ sizeUnitStr: {
56
+ default: 'MB'
57
+ },
58
+ action: ''
59
+ // imgType: {
60
+ // type: Number,
61
+ // default: () => {
62
+ // return 0
63
+ // }
64
+ // }
65
+ },
66
+ data() {
67
+ return {
68
+ fileList: [],
69
+ fileMaxSize: this.maxSize
70
+ }
71
+ },
72
+ watch: {
73
+ imgPath: {
74
+ immediate: true,
75
+ deep: true,
76
+ handler(value) {
77
+ if (value && value.length > 0) {
78
+ this.fileList = [value]
79
+ } else {
80
+ this.fileList = []
81
+ }
82
+ }
83
+ }
84
+ },
85
+ methods: {
86
+ handleRemove(event) {
87
+ this.fileList.splice(event.index, 1)
88
+ this.$emit('img-changed', null)
89
+ },
90
+ handleSuccess(event) {
91
+ this.fileList.push(event.res.data.path)
92
+ // 通过判断是否传入其他的url,来判断,后端的上传图片并不是一个统一的接口,
93
+ let path = event.res.data.path
94
+ if (this.action) {
95
+ path = path + '&imgid=' + event.res.data.id
96
+ }
97
+ // 兼容后端的垃圾设计, 给后端传ID,
98
+ this.$emit('img-changed', path)
99
+ }
100
+ },
101
+ mounted() {}
102
+ }
103
+ </script>
@@ -0,0 +1,68 @@
1
+ <template>
2
+ <upload-file
3
+ @on-remove="handleRemove"
4
+ @on-upload-complete="handleSuccess"
5
+ :showImgList="fileList"
6
+ :maxUploadFiles="maxUploadFiles"
7
+ :add-icon-type="addIconType"
8
+ >
9
+ </upload-file>
10
+ </template>
11
+ <script>
12
+ import UploadFile from '_c/upload-file/upload-file'
13
+ export default {
14
+ name: 'UploadFileV2',
15
+ components: { UploadFile },
16
+ model: {
17
+ prop: 'imgList',
18
+ event: 'img-list-changed'
19
+ },
20
+ props: {
21
+ imgList: {
22
+ type: Array,
23
+ default: () => {
24
+ return []
25
+ }
26
+ },
27
+ addIconType: {
28
+ default: 'ios-camera'
29
+ },
30
+ maxUploadFiles: {
31
+ default: 1
32
+ }
33
+ // imgType: {
34
+ // type: Number,
35
+ // default: () => {
36
+ // return 0
37
+ // }
38
+ // }
39
+ },
40
+ data() {
41
+ return {
42
+ fileList: []
43
+ }
44
+ },
45
+ watch: {
46
+ imgList(value) {
47
+ this.fileList = []
48
+ if (!this.$isEmpty(value)) {
49
+ value.forEach((item) => {
50
+ this.fileList.push(item)
51
+ })
52
+ }
53
+ }
54
+ },
55
+ methods: {
56
+ handleRemove(event) {
57
+ this.fileList.splice(event.index, 1)
58
+ this.$emit('img-list-changed', this.fileList)
59
+ },
60
+ handleSuccess(event) {
61
+ this.fileList.push(event.res.data.path)
62
+ this.$emit('img-list-changed', this.fileList)
63
+ }
64
+ },
65
+ mounted() {
66
+ }
67
+ }
68
+ </script>