@kaiyinchem/ky-uniui 1.0.3

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,191 @@
1
+ <!--批量上传,采用递归的方式-->
2
+ <template>
3
+ <view
4
+ :class="{ start: align === 'left', noMargin }"
5
+ class="batch-pic">
6
+ <view v-for="(img, i) in imageUrls" :key="i" :style="{ width: width + 'rpx', height: width + 'rpx' }" class="batch-items" >
7
+ <image
8
+ :src="img"
9
+ class="batch-img"
10
+ mode="aspectFill"
11
+ @click.stop="viewImg(img, imageUrls)"
12
+ >
13
+ </image>
14
+ <text v-if="!disabled" class="iconfont batch-remove" @click="removeImage(i)">&#xe631;</text>
15
+ </view>
16
+ <text
17
+ v-if="count !== imageUrls.length && !disabled && !$slots.default"
18
+ :style="{'font-size': width + 'rpx', width: width + 'rpx', height: width + 'rpx'}"
19
+ class="batch-items batch-btns iconfont"
20
+ @click="addImage"
21
+ >&#xe8be;</text>
22
+ <slot></slot>
23
+ </view>
24
+ </template>
25
+
26
+ <script>
27
+
28
+ export default {
29
+ emits: ['update:value', 'change'],
30
+ props: {
31
+ width: {
32
+ type: String,
33
+ default: '120',
34
+ },
35
+ value: {
36
+ type: [Array, String],
37
+ default: () => [],
38
+ },
39
+ count: {
40
+ type: Number,
41
+ default: 6,
42
+ },
43
+ disabled: {
44
+ type: Boolean,
45
+ default: false,
46
+ },
47
+ // 对其方式
48
+ align: {
49
+ type: String,
50
+ default: 'right',
51
+ },
52
+ noMargin: {
53
+ type: Boolean,
54
+ default: false,
55
+ },
56
+ tableId: {
57
+ type: String,
58
+ default: '',
59
+ }
60
+ },
61
+ data() {
62
+ return {
63
+ imageUrls: [],
64
+ }
65
+ },
66
+ mounted() {
67
+ this.imageUrls = this.setUrls(this.value)
68
+ },
69
+ watch: {
70
+ value(v) {
71
+ this.imageUrls = this.setUrls(v)
72
+ }
73
+ },
74
+ methods: {
75
+ setUrls(v) {
76
+ if (!v) {
77
+ return []
78
+ }
79
+ if (typeof v === 'string') {
80
+ return [v]
81
+ }
82
+ return v
83
+ },
84
+ removeImage(i) {
85
+ this.imageUrls.splice(i, 1)
86
+ this.$emit('update:value', this.count === 1 ? '' : this.imageUrls)
87
+ console.log(this.imageUrls)
88
+ },
89
+ addImage() {
90
+ uni.chooseImage({
91
+ count: this.count, // 默认 9
92
+ sizeType: ['original', 'compressed'],
93
+ sourceType: ['album', 'camera'],
94
+ success: async (res) => {
95
+ console.log(res)
96
+ const filePath = res.tempFilePaths
97
+ const length = filePath.length
98
+ if (length + this.imageUrls.length > this.count) {
99
+ return this.$toast(`最多可上传${this.count}张图片`)
100
+ }
101
+ // this.imageUrls = filePath
102
+ const data = await this.loopUpload(filePath, 0)
103
+ this.$emit('update:value', this.count > 1 ? this.imageUrls : this.imageUrls[0])
104
+ },
105
+ fail: (res) => {
106
+ console.log(res)
107
+ }
108
+ })
109
+ },
110
+
111
+ /**
112
+ * 递归上传多张图片
113
+ * @param { Array } filePath 文件路径
114
+ * @param { Number } counter 计数
115
+ */
116
+ async loopUpload(filePath, counter) {
117
+ console.log(filePath[counter])
118
+ if (counter === filePath.length) {
119
+ return
120
+ }
121
+ try {
122
+ const url = await this.$api.common.upload(filePath[counter], this.tableId)
123
+ console.log(url)
124
+ if (!url) throw { msg: 'upload fail' }
125
+ counter++
126
+ this.loopUpload(filePath, counter)
127
+ let lastUrl = url
128
+ this.imageUrls.push(lastUrl)
129
+ return lastUrl
130
+ } catch (e) {
131
+ console.log(e)
132
+ return Promise.reject(e)
133
+ }
134
+ },
135
+ viewImg(current, urls) {
136
+ uni.previewImage({ current, urls })
137
+ }
138
+ },
139
+ }
140
+ </script>
141
+
142
+ <style scoped lang="scss">
143
+ .batch-pic {
144
+ display: flex;
145
+ flex-wrap: wrap;
146
+ margin-right: -15rpx;
147
+ justify-content: flex-end;
148
+ &.end {
149
+ justify-content: flex-end;
150
+ }
151
+ &.start {
152
+ justify-content: flex-start;
153
+ }
154
+ .batch-items {
155
+ display: flex;
156
+ margin-right: 15rpx;
157
+ margin-bottom: 15rpx;
158
+ width: 120rpx;
159
+ height: 120rpx;
160
+ border-radius: 6rpx;
161
+ position: relative;
162
+ justify-content: center;
163
+ align-items: center;
164
+ .batch-img {
165
+ width: 100%;
166
+ height: 100%;
167
+ border-radius: 6rpx;
168
+ }
169
+ &:last-child {
170
+ margin: 0;
171
+ }
172
+ .batch-remove {
173
+ color: red;
174
+ font-size: 36rpx;
175
+ position: absolute;
176
+ top: -15rpx;
177
+ right: -15rpx;
178
+ display: block;
179
+ width: 36rpx;
180
+ height: 36rpx;
181
+ border-radius: 50%;
182
+ background: var(--bg-white);
183
+ }
184
+ }
185
+ .batch-btns {
186
+ font-size: 120rpx;
187
+ color: var(--border-1);
188
+ line-height: 120rpx;
189
+ }
190
+ }
191
+ </style>
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@kaiyinchem/ky-uniui",
3
+ "author": "kaiyin team",
4
+ "private": false,
5
+ "files": [
6
+ "components",
7
+ "style"
8
+ ],
9
+ "description": "an uniapp ui",
10
+ "version": "1.0.3",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/yezipi/ky-uniui.git"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "keywords": [
19
+ "uniapp"
20
+ ],
21
+ "bugs": {
22
+ "url": "https://github.com/yezipi/ky-uniui/issues"
23
+ },
24
+ "homepage": "https://github.com/yezipi/ky-uniui#readme",
25
+ "scripts": {
26
+ },
27
+ "license": "ISC"
28
+ }
package/style/var.css ADDED
@@ -0,0 +1,85 @@
1
+ page, body {
2
+
3
+ --rgb-primary: 0, 178, 169;
4
+ --rgb-light-primary: 0, 217, 212;
5
+ --rgb-white: 255, 255, 255;
6
+ --rgb-dark: 51, 51, 51;
7
+ --rgb-sub: 51, 163, 255;
8
+ --rgb-gray: 242,242,242;
9
+ --rgb-light-gray: 200, 200, 200;
10
+
11
+ --space-5: 5rpx;
12
+ --space-10: 10rpx;
13
+ --space-15: 15rpx;
14
+ --space-20: 20rpx;
15
+ --space-25: 25rpx;
16
+ --space-30: 30rpx;
17
+
18
+ --color-dark: rgb(var(--rgb-dark));
19
+ --color-white: rgb(var(--rgb-white));
20
+ --color-primary: rgb(var(--rgb-primary));
21
+ --color-light-primary: rgb(var(--rgb-light-primary));
22
+ --color-primary-05: rgba(var(--rgb-primary), 0.5);
23
+ --color-primary-01: rgba(var(--rgb-primary), 0.1);
24
+ --color-gray: rgba(var(--rgb-dark), 0.6);
25
+ --color-link: rgb(var(--rgb-sub));
26
+ --color-light-gray: rgb(var(--rgb-light-gray));
27
+ --color-price: #E02020;
28
+
29
+ --bg-white: rgb(var(--rgb-white));
30
+ --bg-gray: rgba(var(--rgb-gray));
31
+
32
+ --border-1: rgba(var(--rgb-dark), 0.1);
33
+ --border-2: rgba(var(--rgb-dark), 0.2);
34
+
35
+ --font-20: 20rpx;
36
+ --font-22: 22rpx;
37
+ --font-24: 24rpx;
38
+ --font-26: 26rpx;
39
+ --font-28: 28rpx;
40
+ --font-30: 30rpx;
41
+ --font-32: 32rpx;
42
+ --font-34: 34rpx;
43
+ --font-36: 36rpx;
44
+ --font-38: 38rpx;
45
+ --font-40: 40rpx;
46
+ --border-radius: 5rpx;
47
+
48
+ }
49
+
50
+ /* Dark mode */
51
+ @media (prefers-color-scheme: dark) {
52
+ body, uni-page-head .uni-page-head, uni-page-body, .w-picker-header, .uni-picker-view-content {
53
+ background: #222222!important;
54
+ }
55
+ page, body {
56
+ --rgb-white: 55, 55, 55;
57
+ --rgb-dark: 180, 180, 180;
58
+ --rgb-gray: 30, 30, 30;
59
+ --rgb-light-gray: 80, 80, 80;
60
+ --rgb-primary: 0, 150, 150;
61
+ --rgb-light-primary: 0, 120, 120;
62
+ }
63
+ uni-page-head .uni-page-head__title,
64
+ uni-page-head .uni-btn-icon {
65
+ color: var(--color-dark)!important;
66
+ }
67
+ .ky-tag-orange, .product-notice {
68
+ background: #3a271e!important;
69
+ color: #e28d63!important;
70
+ }
71
+ .uni-picker-container .uni-picker-item {
72
+ color: #f5f5f5!important;
73
+ }
74
+ .uni-picker-view-mask {
75
+ background-image: linear-gradient(
76
+ 180deg,
77
+ rgba(35, 35, 35, 0.95),
78
+ rgb(0 0 0 / 60%)
79
+ ),
80
+ linear-gradient(0deg, rgb(0 0 0 / 100%), rgb(0 0 0 / 60%))!important;
81
+ }
82
+ .w-picker-header {
83
+ border-bottom: var(--border-1)!important;
84
+ }
85
+ }