@zfqh/uniapp 0.1.1

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.
Files changed (310) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -0
  4. package/docs/api/apis/core.md +189 -0
  5. package/docs/api/apis/index.md +82 -0
  6. package/docs/api/apis/request.md +369 -0
  7. package/docs/api/configs/api.md +32 -0
  8. package/docs/api/configs/app.md +43 -0
  9. package/docs/api/configs/brand.md +43 -0
  10. package/docs/api/configs/cdn.md +35 -0
  11. package/docs/api/configs/color.md +144 -0
  12. package/docs/api/configs/env.md +120 -0
  13. package/docs/api/configs/index.md +394 -0
  14. package/docs/api/configs/link.md +33 -0
  15. package/docs/api/configs/log.md +27 -0
  16. package/docs/api/configs/mp.md +34 -0
  17. package/docs/api/configs/navigate.md +27 -0
  18. package/docs/api/configs/page.md +32 -0
  19. package/docs/api/configs/path.md +27 -0
  20. package/docs/api/configs/storage.md +24 -0
  21. package/docs/api/configs/tabbar.md +29 -0
  22. package/docs/api/configs/toast.md +35 -0
  23. package/docs/api/configs/update.md +25 -0
  24. package/docs/api/configs/upload.md +45 -0
  25. package/docs/api/configs/ver.md +32 -0
  26. package/docs/api/configs/web.md +28 -0
  27. package/docs/api/hooks/index.md +182 -0
  28. package/docs/api/hooks/useI18n.md +27 -0
  29. package/docs/api/hooks/useOverlay.md +37 -0
  30. package/docs/api/hooks/usePopup.md +35 -0
  31. package/docs/api/hooks/useVersion.md +23 -0
  32. package/docs/api/index.md +269 -0
  33. package/docs/api/mixins/app.md +29 -0
  34. package/docs/api/mixins/badge.md +23 -0
  35. package/docs/api/mixins/debounce.md +32 -0
  36. package/docs/api/mixins/deep.md +29 -0
  37. package/docs/api/mixins/index.md +23 -0
  38. package/docs/api/mixins/login.md +22 -0
  39. package/docs/api/mixins/model.md +26 -0
  40. package/docs/api/mixins/redirect.md +26 -0
  41. package/docs/api/mixins/share.md +29 -0
  42. package/docs/api/mixins/show.md +27 -0
  43. package/docs/api/mixins/webview.md +27 -0
  44. package/docs/api/modules/app.md +30 -0
  45. package/docs/api/modules/dict.md +28 -0
  46. package/docs/api/modules/im.md +22 -0
  47. package/docs/api/modules/index.md +44 -0
  48. package/docs/api/modules/launch.md +26 -0
  49. package/docs/api/modules/location.md +25 -0
  50. package/docs/api/modules/login.md +35 -0
  51. package/docs/api/modules/network.md +26 -0
  52. package/docs/api/modules/system.md +29 -0
  53. package/docs/api/utils/audio.md +84 -0
  54. package/docs/api/utils/consts.md +201 -0
  55. package/docs/api/utils/cos.md +269 -0
  56. package/docs/api/utils/debounce.md +89 -0
  57. package/docs/api/utils/file.md +78 -0
  58. package/docs/api/utils/index.md +547 -0
  59. package/docs/api/utils/locale.md +32 -0
  60. package/docs/api/utils/message.md +81 -0
  61. package/docs/api/utils/navigate.md +267 -0
  62. package/docs/api/utils/pages.md +205 -0
  63. package/docs/api/utils/permission.md +28 -0
  64. package/docs/api/utils/permit.md +62 -0
  65. package/docs/api/utils/query.md +89 -0
  66. package/docs/api/utils/request.md +34 -0
  67. package/docs/api/utils/storage.md +145 -0
  68. package/docs/api/utils/subscribe.md +77 -0
  69. package/docs/api/utils/throttle.md +101 -0
  70. package/docs/api/utils/toast.md +164 -0
  71. package/docs/api/utils/uni.md +28 -0
  72. package/docs/api/utils/update.md +165 -0
  73. package/docs/components/g-back-button.md +76 -0
  74. package/docs/components/g-checkbox-list.md +101 -0
  75. package/docs/components/g-container.md +93 -0
  76. package/docs/components/g-data-list.md +106 -0
  77. package/docs/components/g-dot-text.md +79 -0
  78. package/docs/components/g-env.md +75 -0
  79. package/docs/components/g-float.md +83 -0
  80. package/docs/components/g-grid-image.md +91 -0
  81. package/docs/components/g-grid-swiper.md +99 -0
  82. package/docs/components/g-icon.md +106 -0
  83. package/docs/components/g-mask.md +82 -0
  84. package/docs/components/g-money.md +90 -0
  85. package/docs/components/g-more.md +78 -0
  86. package/docs/components/g-page-container.md +170 -0
  87. package/docs/components/g-permission-popup.md +117 -0
  88. package/docs/components/g-polyline-chat.md +102 -0
  89. package/docs/components/g-polyline-view.md +67 -0
  90. package/docs/components/g-popup.md +144 -0
  91. package/docs/components/g-refresh-view.md +118 -0
  92. package/docs/components/g-render-image.md +83 -0
  93. package/docs/components/g-search.md +120 -0
  94. package/docs/components/g-share-photo.md +77 -0
  95. package/docs/components/g-share-view.md +83 -0
  96. package/docs/components/g-share-weixin.md +81 -0
  97. package/docs/components/g-skeleton-view.md +71 -0
  98. package/docs/components/g-skeleton.md +64 -0
  99. package/docs/components/g-tag-editor.md +134 -0
  100. package/docs/components/g-timer.md +72 -0
  101. package/docs/components/g-trtc-room.md +116 -0
  102. package/docs/components/g-trtc-tui.md +84 -0
  103. package/docs/components/g-trtc.md +124 -0
  104. package/docs/components/g-upload.md +117 -0
  105. package/docs/components/g-waterfall.md +84 -0
  106. package/docs/components/index.md +109 -0
  107. package/docs/components/styles/base-styles.md +367 -0
  108. package/docs/components/styles/global-vars.md +150 -0
  109. package/docs/components/usage.md +112 -0
  110. package/docs/faq/index.md +78 -0
  111. package/docs/guide/getting-started.md +195 -0
  112. package/docs/guide/project-frame.md +297 -0
  113. package/docs/index.md +80 -0
  114. package/lib/apis/core.d.ts +12 -0
  115. package/lib/apis/core.js +13 -0
  116. package/lib/apis/index.d.ts +2 -0
  117. package/lib/apis/index.js +2 -0
  118. package/lib/apis/request.d.ts +4 -0
  119. package/lib/apis/request.js +27 -0
  120. package/lib/components/g-back-button/g-back-button.vue +141 -0
  121. package/lib/components/g-checkbox-list/g-checkbox-list.vue +156 -0
  122. package/lib/components/g-container/g-container.vue +159 -0
  123. package/lib/components/g-data-list/g-data-list.vue +192 -0
  124. package/lib/components/g-dot-text/g-dot-text.vue +114 -0
  125. package/lib/components/g-env/g-env.vue +123 -0
  126. package/lib/components/g-float/g-float.vue +131 -0
  127. package/lib/components/g-grid-image/g-grid-image.vue +84 -0
  128. package/lib/components/g-grid-swiper/g-grid-swiper.vue +224 -0
  129. package/lib/components/g-icon/g-icon.vue +72 -0
  130. package/lib/components/g-mask/g-mask.vue +126 -0
  131. package/lib/components/g-money/g-money.vue +174 -0
  132. package/lib/components/g-more/g-more.vue +68 -0
  133. package/lib/components/g-page-container/g-page-container.vue +470 -0
  134. package/lib/components/g-permission-popup/g-permission-popup.vue +80 -0
  135. package/lib/components/g-polyline-chat/g-polyline-chat.vue +255 -0
  136. package/lib/components/g-polyline-view/g-polyline-view.vue +104 -0
  137. package/lib/components/g-popup/g-popup.vue +449 -0
  138. package/lib/components/g-refresh-view/g-refresh-view.vue +213 -0
  139. package/lib/components/g-render-image/g-render-image.vue +222 -0
  140. package/lib/components/g-search/g-search.vue +274 -0
  141. package/lib/components/g-share-photo/g-share-photo.vue +75 -0
  142. package/lib/components/g-share-view/g-share-view.vue +157 -0
  143. package/lib/components/g-share-weixin/g-share-weixin.vue +106 -0
  144. package/lib/components/g-skeleton/g-skeleton.vue +55 -0
  145. package/lib/components/g-skeleton-view/g-skeleton-view.vue +78 -0
  146. package/lib/components/g-tag-editor/g-tag-editor.vue +482 -0
  147. package/lib/components/g-timer/g-timer.vue +61 -0
  148. package/lib/components/g-trtc/g-trtc.vue +347 -0
  149. package/lib/components/g-trtc-room/g-trtc-room.vue +524 -0
  150. package/lib/components/g-trtc-room/iconfont.scss +59 -0
  151. package/lib/components/g-trtc-tui/g-trtc-tui.vue +245 -0
  152. package/lib/components/g-upload/g-upload.vue +294 -0
  153. package/lib/components/g-waterfall/g-waterfall.vue +101 -0
  154. package/lib/configs/api.d.ts +7 -0
  155. package/lib/configs/api.js +6 -0
  156. package/lib/configs/app.d.ts +26 -0
  157. package/lib/configs/app.js +50 -0
  158. package/lib/configs/brand.d.ts +22 -0
  159. package/lib/configs/brand.js +26 -0
  160. package/lib/configs/cdn.d.ts +13 -0
  161. package/lib/configs/cdn.js +12 -0
  162. package/lib/configs/color.d.ts +62 -0
  163. package/lib/configs/color.js +66 -0
  164. package/lib/configs/env.d.ts +37 -0
  165. package/lib/configs/env.js +71 -0
  166. package/lib/configs/index.d.ts +170 -0
  167. package/lib/configs/index.js +82 -0
  168. package/lib/configs/link.d.ts +11 -0
  169. package/lib/configs/link.js +3 -0
  170. package/lib/configs/log.d.ts +9 -0
  171. package/lib/configs/log.js +8 -0
  172. package/lib/configs/mp.d.ts +15 -0
  173. package/lib/configs/mp.js +9 -0
  174. package/lib/configs/navigate.d.ts +17 -0
  175. package/lib/configs/navigate.js +5 -0
  176. package/lib/configs/page.d.ts +18 -0
  177. package/lib/configs/page.js +14 -0
  178. package/lib/configs/path.d.ts +11 -0
  179. package/lib/configs/path.js +10 -0
  180. package/lib/configs/storage.d.ts +7 -0
  181. package/lib/configs/storage.js +6 -0
  182. package/lib/configs/tabbar.d.ts +7 -0
  183. package/lib/configs/tabbar.js +6 -0
  184. package/lib/configs/toast.d.ts +18 -0
  185. package/lib/configs/toast.js +29 -0
  186. package/lib/configs/update.d.ts +45 -0
  187. package/lib/configs/update.js +6 -0
  188. package/lib/configs/upload.d.ts +30 -0
  189. package/lib/configs/upload.js +7 -0
  190. package/lib/configs/ver.d.ts +8 -0
  191. package/lib/configs/ver.js +28 -0
  192. package/lib/configs/web.d.ts +5 -0
  193. package/lib/configs/web.js +2 -0
  194. package/lib/hooks/index.d.ts +4 -0
  195. package/lib/hooks/index.js +4 -0
  196. package/lib/hooks/useI18n.d.ts +2 -0
  197. package/lib/hooks/useI18n.js +19 -0
  198. package/lib/hooks/useOverlay.d.ts +1 -0
  199. package/lib/hooks/useOverlay.js +17 -0
  200. package/lib/hooks/usePopup.d.ts +1 -0
  201. package/lib/hooks/usePopup.js +14 -0
  202. package/lib/hooks/useVersion.d.ts +6 -0
  203. package/lib/hooks/useVersion.js +21 -0
  204. package/lib/index.d.ts +26 -0
  205. package/lib/index.js +33 -0
  206. package/lib/mixins/app.d.ts +14 -0
  207. package/lib/mixins/app.js +105 -0
  208. package/lib/mixins/badge.d.ts +24 -0
  209. package/lib/mixins/badge.js +44 -0
  210. package/lib/mixins/debounce.d.ts +6 -0
  211. package/lib/mixins/debounce.js +11 -0
  212. package/lib/mixins/deep.d.ts +6 -0
  213. package/lib/mixins/deep.js +8 -0
  214. package/lib/mixins/index.d.ts +8 -0
  215. package/lib/mixins/index.js +8 -0
  216. package/lib/mixins/login.d.ts +4 -0
  217. package/lib/mixins/login.js +25 -0
  218. package/lib/mixins/model.d.ts +22 -0
  219. package/lib/mixins/model.js +29 -0
  220. package/lib/mixins/redirect.d.ts +8 -0
  221. package/lib/mixins/redirect.js +94 -0
  222. package/lib/mixins/share.d.ts +15 -0
  223. package/lib/mixins/share.js +55 -0
  224. package/lib/mixins/show.d.ts +9 -0
  225. package/lib/mixins/show.js +16 -0
  226. package/lib/mixins/webview.d.ts +26 -0
  227. package/lib/mixins/webview.js +225 -0
  228. package/lib/modules/app.d.ts +5 -0
  229. package/lib/modules/app.js +19 -0
  230. package/lib/modules/dict.d.ts +8 -0
  231. package/lib/modules/dict.js +43 -0
  232. package/lib/modules/im.d.ts +6 -0
  233. package/lib/modules/im.js +105 -0
  234. package/lib/modules/index.d.ts +8 -0
  235. package/lib/modules/index.js +8 -0
  236. package/lib/modules/launch.d.ts +5 -0
  237. package/lib/modules/launch.js +32 -0
  238. package/lib/modules/location.d.ts +5 -0
  239. package/lib/modules/location.js +57 -0
  240. package/lib/modules/login.d.ts +5 -0
  241. package/lib/modules/login.js +72 -0
  242. package/lib/modules/network.d.ts +5 -0
  243. package/lib/modules/network.js +39 -0
  244. package/lib/modules/system.d.ts +5 -0
  245. package/lib/modules/system.js +65 -0
  246. package/lib/styles/animate-vue.scss +3 -0
  247. package/lib/styles/animate.scss +27 -0
  248. package/lib/styles/bg-vue.scss +21 -0
  249. package/lib/styles/bg.scss +93 -0
  250. package/lib/styles/border.scss +218 -0
  251. package/lib/styles/flex-nvue.scss +64 -0
  252. package/lib/styles/flex-vue.scss +75 -0
  253. package/lib/styles/font.scss +59 -0
  254. package/lib/styles/index.scss +25 -0
  255. package/lib/styles/layout-nvue.scss +24 -0
  256. package/lib/styles/layout-vue.scss +30 -0
  257. package/lib/styles/layout.scss +76 -0
  258. package/lib/styles/opacity.scss +10 -0
  259. package/lib/styles/reset-vue.scss +46 -0
  260. package/lib/styles/shadow.scss +12 -0
  261. package/lib/styles/sizing-vue.scss +21 -0
  262. package/lib/styles/sizing.scss +21 -0
  263. package/lib/styles/spacing.scss +234 -0
  264. package/lib/styles/text-nvue.scss +21 -0
  265. package/lib/styles/text-vue.scss +70 -0
  266. package/lib/styles/text.scss +122 -0
  267. package/lib/styles/var.module.scss +29 -0
  268. package/lib/utils/audio.d.ts +14 -0
  269. package/lib/utils/audio.js +43 -0
  270. package/lib/utils/consts.d.ts +30 -0
  271. package/lib/utils/consts.js +52 -0
  272. package/lib/utils/cos.d.ts +15 -0
  273. package/lib/utils/cos.js +140 -0
  274. package/lib/utils/debounce.d.ts +2 -0
  275. package/lib/utils/debounce.js +30 -0
  276. package/lib/utils/file.d.ts +28 -0
  277. package/lib/utils/file.js +292 -0
  278. package/lib/utils/index.d.ts +166 -0
  279. package/lib/utils/index.js +485 -0
  280. package/lib/utils/locale.d.ts +6 -0
  281. package/lib/utils/locale.js +19 -0
  282. package/lib/utils/message.d.ts +9 -0
  283. package/lib/utils/message.js +63 -0
  284. package/lib/utils/navigate.d.ts +27 -0
  285. package/lib/utils/navigate.js +183 -0
  286. package/lib/utils/pages.d.ts +21 -0
  287. package/lib/utils/pages.js +79 -0
  288. package/lib/utils/permission.d.ts +16 -0
  289. package/lib/utils/permission.js +291 -0
  290. package/lib/utils/permit.d.ts +30 -0
  291. package/lib/utils/permit.js +181 -0
  292. package/lib/utils/query.d.ts +13 -0
  293. package/lib/utils/query.js +14 -0
  294. package/lib/utils/request.d.ts +8 -0
  295. package/lib/utils/request.js +126 -0
  296. package/lib/utils/storage.d.ts +53 -0
  297. package/lib/utils/storage.js +145 -0
  298. package/lib/utils/subscribe.d.ts +7 -0
  299. package/lib/utils/subscribe.js +94 -0
  300. package/lib/utils/throttle.d.ts +2 -0
  301. package/lib/utils/throttle.js +32 -0
  302. package/lib/utils/toast.d.ts +17 -0
  303. package/lib/utils/toast.js +66 -0
  304. package/lib/utils/uni.d.ts +1 -0
  305. package/lib/utils/uni.js +147 -0
  306. package/lib/utils/update.d.ts +9 -0
  307. package/lib/utils/update.js +376 -0
  308. package/package.json +49 -0
  309. package/types/index.d.ts +25 -0
  310. package/types/virtual.d.ts +1 -0
@@ -0,0 +1,222 @@
1
+ <template>
2
+ <view class="render-image">
3
+ <view :prop="domId" :change:prop="renderImage.watchDomId">
4
+ <slot name="default"></slot>
5
+ <text :prop="count" :change:prop="renderImage.watchCount"></text>
6
+ </view>
7
+ <!-- #ifdef H5 -->
8
+ <uv-overlay :show="show" @click="show = false">
9
+ <view class="flex flex-col justify-center items-center h-full">
10
+ <view :style="[contentStyle]" class="overflow-hidden">
11
+ <image
12
+ v-if="path"
13
+ :src="path"
14
+ :style="[imageStyle]"
15
+ style="width: 80vw; max-height: 85vh"
16
+ show-menu-by-longpress
17
+ mode="widthFix"
18
+ @tap.stop
19
+ />
20
+ </view>
21
+ <text class="text-28rpx text-white mt-20rpx"> {{ saveTips }} </text>
22
+ <view style="transform: translateY(30rpx)">
23
+ <uv-icon name="close-circle" color="#fff" size="48rpx" @click.stop="show = false" />
24
+ </view>
25
+ </view>
26
+ </uv-overlay>
27
+ <!-- #endif -->
28
+ </view>
29
+ </template>
30
+
31
+ <script>
32
+ import toast from '../../utils/toast';
33
+ import { base64ToPath } from '../../utils/file';
34
+ import { WEBVIEW_ENV } from '../../utils/consts';
35
+ import { postMessage, requestDelay } from '../../utils';
36
+ import { requestPermission } from '../../utils/permit';
37
+ import { TYPES } from '../../utils/message';
38
+
39
+ export default {
40
+ props: {
41
+ domId: {
42
+ type: String,
43
+ default: '',
44
+ },
45
+ name: {
46
+ type: String,
47
+ default: '',
48
+ },
49
+ successTips: {
50
+ type: String,
51
+ default: '已保存到相册',
52
+ },
53
+ saveTips: {
54
+ type: String,
55
+ default: '长按图片保存到相册',
56
+ },
57
+ contentStyle: {
58
+ type: Object,
59
+ default: () => ({}),
60
+ },
61
+ imageStyle: {
62
+ type: Object,
63
+ default: () => ({}),
64
+ },
65
+ },
66
+ data() {
67
+ return {
68
+ path: '',
69
+ count: 0,
70
+ // #ifdef H5
71
+ show: false,
72
+ // #endif
73
+ // #ifndef H5
74
+ resolve: null,
75
+ reject: null,
76
+ // #endif
77
+ };
78
+ },
79
+ // #ifdef H5
80
+ watch: {
81
+ domId: {
82
+ immediate: true,
83
+ handler(...args) {
84
+ this.watchDomId(...args);
85
+ },
86
+ },
87
+ },
88
+ // #endif
89
+ methods: {
90
+ // #ifndef H5
91
+ setResolve(e) {
92
+ this.resolve(e);
93
+ },
94
+ setReject(e) {
95
+ this.reject(new Error(e));
96
+ },
97
+ // #endif
98
+ async getBase64() {
99
+ let base64 = '';
100
+ // #ifdef H5
101
+ base64 = await this.renderImage();
102
+ // #endif
103
+ // #ifndef H5
104
+ this.count++;
105
+ base64 = await new Promise((resolve, reject) => {
106
+ this.resolve = resolve;
107
+ this.reject = reject;
108
+ });
109
+ // #endif
110
+ return base64;
111
+ },
112
+ async download() {
113
+ try {
114
+ uni.showLoading({ mask: true });
115
+ await requestDelay(() => Promise.resolve());
116
+ const base64 = await this.getBase64();
117
+ let path = '';
118
+
119
+ if (WEBVIEW_ENV.mp || WEBVIEW_ENV.app) {
120
+ path = base64;
121
+ } else {
122
+ path = await base64ToPath(base64);
123
+ }
124
+
125
+ this.path = path;
126
+
127
+ if (WEBVIEW_ENV.mp) {
128
+ this.show = true;
129
+ } else if (WEBVIEW_ENV.app) {
130
+ postMessage({
131
+ type: TYPES.SAVE_IMAGE,
132
+ payload: {
133
+ data: path,
134
+ },
135
+ });
136
+ // 延迟1秒等待app保存图片
137
+ await requestDelay(() => Promise.resolve(), 1000);
138
+ } else {
139
+ // #ifdef H5
140
+ const node = document.createElement('a');
141
+ node.href = path;
142
+ node.download = `${this.name || uni.$uv.timeFormat(Date.now(), 'yyyymmddhhMMss')}.png`;
143
+ node.click();
144
+ // #endif
145
+ // #ifndef H5
146
+ await requestPermission('storage');
147
+ uni.saveImageToPhotosAlbum({
148
+ filePath: path,
149
+ success() {
150
+ uni.showToast({
151
+ title: this.successTips,
152
+ position: 'bottom',
153
+ });
154
+ },
155
+ });
156
+ // #endif
157
+ }
158
+ } catch (e) {
159
+ toast.message(e.message);
160
+ } finally {
161
+ uni.hideLoading();
162
+ }
163
+ },
164
+ },
165
+ };
166
+ </script>
167
+
168
+ <script module="renderImage" lang="renderjs">
169
+ import html2canvas from 'html2canvas';
170
+
171
+ export default {
172
+ data() {
173
+ return {
174
+ renderDomId: '',
175
+ };
176
+ },
177
+ methods: {
178
+ async renderImage() {
179
+ try {
180
+ const el = document.getElementById(this.renderDomId);
181
+ if(!el) {
182
+ throw new Error('DOM未加载成功,请检查domId是否有误!');
183
+ }
184
+ const canvas = await html2canvas(el, {
185
+ width: el.offsetWidth,
186
+ height: el.offsetHeight,
187
+ x: 0,
188
+ y: 0,
189
+ useCORS: true,
190
+ scale: 2,
191
+ });
192
+ const base64 = canvas.toDataURL('image/png', 1.0);
193
+ // #ifndef H5
194
+ this.$ownerInstance.callMethod('setResolve', base64);
195
+ // #endif
196
+ // #ifdef H5
197
+ return base64;
198
+ // #endif
199
+ } catch(e) {
200
+ // #ifdef H5
201
+ throw e;
202
+ // #endif
203
+ // #ifndef H5
204
+ this.$ownerInstance.callMethod('setReject', e.message);
205
+ // #endif
206
+ }
207
+ },
208
+ watchDomId(newValue) {
209
+ this.renderDomId = newValue;
210
+ },
211
+ // #ifndef H5
212
+ watchCount(newValue) {
213
+ if(newValue !== 0) {
214
+ this.renderImage();
215
+ }
216
+ },
217
+ // #endif
218
+ }
219
+ }
220
+ </script>
221
+
222
+ <style lang="scss" scoped></style>
@@ -0,0 +1,274 @@
1
+ <template>
2
+ <view class="search-input flex" @tap="click()" :style="[style]" :class="[shape]">
3
+ <slot name="icon">
4
+ <uv-icon name="search" size="20" class="text-tips" />
5
+ </slot>
6
+ <swiper
7
+ v-if="keywords"
8
+ class="flex-1 h-full"
9
+ :current="current"
10
+ autoplay
11
+ vertical
12
+ circular
13
+ disable-touch
14
+ @change="change"
15
+ >
16
+ <swiper-item v-for="(keyword, index) in data" :key="index">
17
+ <text class="ml-16rpx flex h-full" :style="[_inputStyle, _placeholderStyle]"> {{ keyword }} </text>
18
+ </swiper-item>
19
+ </swiper>
20
+ <view v-else class="flex-1 ml-16rpx h-full relative">
21
+ <input
22
+ v-model.trim="keyword"
23
+ :placeholder="placeholder"
24
+ @tap.stop
25
+ :placeholder-style="inputPlaceholderStyle"
26
+ :placeholder-class="placeholderClass"
27
+ class="h-full search-input-text"
28
+ :style="[_inputStyle]"
29
+ :auto-focus="autoFocus"
30
+ confirm-type="search"
31
+ :maxlength="maxlength"
32
+ @confirm="search()"
33
+ @input="input()"
34
+ />
35
+ <view v-if="clearable" class="search-input-clear" @tap.stop="clear" :style="[closeStyle]">
36
+ <uv-icon v-if="keyword" name="close-circle-fill" class="flex text-tips" :size="clearSize" />
37
+ </view>
38
+ </view>
39
+ <view v-if="showButton" @tap.stop="search()">
40
+ <slot name="button">
41
+ <view class="flex" :style="[buttonStyle]">
42
+ <uv-line direction="col" :color="lineColor" length="26" margin="0 16rpx" />
43
+ <text class="text-26rpx"> 搜索 </text>
44
+ </view>
45
+ </slot>
46
+ </view>
47
+ </view>
48
+ </template>
49
+
50
+ <script>
51
+ import color from '../../configs/color';
52
+ import model from '../../mixins/model';
53
+
54
+ export default {
55
+ mixins: [
56
+ model({
57
+ type: String,
58
+ default: '',
59
+ }),
60
+ ],
61
+ props: {
62
+ placeholder: String,
63
+ height: {
64
+ type: [String, Number],
65
+ default: 35,
66
+ },
67
+ customStyle: {
68
+ type: Object,
69
+ default: () => ({}),
70
+ },
71
+ inputStyle: {
72
+ type: Object,
73
+ default: () => ({}),
74
+ },
75
+ buttonStyle: {
76
+ type: Object,
77
+ default: () => ({}),
78
+ },
79
+ showButton: {
80
+ type: Boolean,
81
+ default: false,
82
+ },
83
+ fontSize: {
84
+ type: [String, Number],
85
+ default: 14,
86
+ },
87
+ bgColor: {
88
+ type: String,
89
+ default: '#fff',
90
+ },
91
+ lineColor: {
92
+ type: String,
93
+ default: '#ECEDF0',
94
+ },
95
+ borderColor: {
96
+ type: String,
97
+ default: () => color.primary,
98
+ },
99
+ placeholderStyle: {
100
+ type: Object,
101
+ default: () => ({}),
102
+ },
103
+ placeholderClass: {
104
+ type: String,
105
+ default: '',
106
+ },
107
+ border: {
108
+ type: [Boolean, Number],
109
+ default: true,
110
+ },
111
+ maxlength: {
112
+ type: [String, Number],
113
+ default: 100,
114
+ },
115
+ borderRadius: {
116
+ type: [String, Number],
117
+ default: 4,
118
+ },
119
+ clearSize: {
120
+ type: [String, Number],
121
+ default: 15,
122
+ },
123
+ shape: {
124
+ type: String,
125
+ default: 'square',
126
+ },
127
+ keywords: {
128
+ type: [Boolean, Array],
129
+ default: () => false,
130
+ },
131
+ params: {
132
+ type: Object,
133
+ default: () => ({}),
134
+ },
135
+ autoFocus: Boolean,
136
+ clearable: Boolean,
137
+ },
138
+ data() {
139
+ let keyword = '';
140
+ let data = [];
141
+ if (Array.isArray(this.keywords)) {
142
+ keyword = this.keywords[0] || '';
143
+ data = [...this.keywords];
144
+ } else {
145
+ // #ifdef VUE2
146
+ keyword = this.value;
147
+ // #endif
148
+ // #ifdef VUE3
149
+ keyword = this.modelValue;
150
+ // #endif
151
+ }
152
+ return {
153
+ current: 0,
154
+ keyword,
155
+ data,
156
+ };
157
+ },
158
+ watch: {
159
+ value(e) {
160
+ this.keyword = e;
161
+ },
162
+ keyword(e) {
163
+ this.updateModel(e);
164
+ },
165
+ current() {
166
+ this.setKeyword();
167
+ },
168
+ keywords: {
169
+ immediate: true,
170
+ handler(e) {
171
+ if (Array.isArray(e)) {
172
+ this.data = e;
173
+ } else if (e) {
174
+ this.data = [];
175
+ }
176
+ },
177
+ },
178
+ data() {
179
+ this.current = 0;
180
+ this.setKeyword();
181
+ },
182
+ },
183
+ computed: {
184
+ style() {
185
+ return Object.assign(
186
+ {
187
+ backgroundColor: this.bgColor,
188
+ borderColor: this.borderColor,
189
+ borderRadius: uni.$uv.addUnit(this.borderRadius),
190
+ height: uni.$uv.addUnit(this.height),
191
+ borderWidth: `${Number(this.border)}rpx`,
192
+ },
193
+ this.customStyle,
194
+ );
195
+ },
196
+ closeStyle() {
197
+ return {
198
+ background: this.bgColor,
199
+ };
200
+ },
201
+ _placeholderStyle() {
202
+ return Object.assign({ color: '#9a9a9a' }, this.placeholderStyle);
203
+ },
204
+ inputPlaceholderStyle() {
205
+ const styles = [];
206
+ const style = this._placeholderStyle;
207
+ Object.keys(style).forEach((key) => {
208
+ styles.push(`${key}:${style[key]}`);
209
+ });
210
+ return styles.join(';');
211
+ },
212
+ _inputStyle() {
213
+ return Object.assign(
214
+ {
215
+ fontSize: uni.$uv.addUnit(this.fontSize),
216
+ },
217
+ this.inputStyle,
218
+ );
219
+ },
220
+ },
221
+ methods: {
222
+ setKeyword() {
223
+ this.keyword = this.data[this.current] || '';
224
+ },
225
+ change({ detail }) {
226
+ this.current = detail.current;
227
+ },
228
+ click() {
229
+ this.$emit('search', this.keyword, 0);
230
+ },
231
+ search() {
232
+ this.$emit('search', this.keyword, 1);
233
+ },
234
+ input() {
235
+ this.$emit('input', this.keyword);
236
+ },
237
+ clear() {
238
+ this.$emit('input', (this.keyword = ''));
239
+ this.$emit('clear');
240
+ },
241
+ },
242
+ };
243
+ </script>
244
+
245
+ <style lang="scss" scoped>
246
+ .search-input {
247
+ width: 100%;
248
+ border-style: solid;
249
+ border-color: transparent;
250
+ padding: 0 20rpx;
251
+ overflow: hidden;
252
+ box-sizing: border-box;
253
+ & > input {
254
+ height: 100%;
255
+ }
256
+ &.square {
257
+ border-radius: 8rpx;
258
+ }
259
+ &.circle {
260
+ border-radius: 100rpx !important;
261
+ }
262
+ &-clear {
263
+ position: absolute;
264
+ right: -16rpx;
265
+ top: 4rpx;
266
+ bottom: 4rpx;
267
+ padding: 0 16rpx;
268
+ z-index: 2;
269
+ display: flex;
270
+ justify-content: center;
271
+ align-items: center;
272
+ }
273
+ }
274
+ </style>
@@ -0,0 +1,75 @@
1
+ <template>
2
+ <view class="flex justify-center flex-col" :style="[customStyle]" @tap.stop="$uv.throttle(click)">
3
+ <image :src="url" :style="[style]" mode="heightFix" />
4
+ <text v-if="text" :style="[textStyle]"> {{ text }} </text>
5
+ </view>
6
+ </template>
7
+
8
+ <script>
9
+ export default {
10
+ props: {
11
+ size: {
12
+ type: [Number, String],
13
+ default: 40,
14
+ },
15
+ url: {
16
+ type: String,
17
+ default:
18
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAMAAAC5zwKfAAAAe1BMVEVHcEz29vb29vb39/f39/f29vb29vb39/f29vb29vb29vb29vb29vb39/f29vb39/f29vb39/f6+vn49/f29vbw8PDp6ezb3eTQ0dO5xeGusLOZsOqjpKigoKSNj5Vmi+ODhYqAgoh9f4R3eX9zdXxvcXhEcd5rbXQaUdgrKM5JAAAAEnRSTlMABxMjOFVkdY2epaqwxdPc7feYI9LvAAAC+UlEQVR42rWZ23arIBCGVYwxadABBhNzbk7m/Z9wb7pXSrtABrvp34t69a2PkMDMmIWSF6ys6iVvAQRA2/BlXZWsyLOfpWCz+oOFnzFYXs9YMZ2Ws9miNSw3AtrFjOUTcXNuaT4mn7N8Cq4BJAJNNLKoOGBEgFdFjF65BIwMLMuc1msERkc0lCSrAScFahbilSuBEyNWZYDHBU6O4OU4D38UXhK8BETLS0dkxH4QO+PsdVETPIJYF995eQXoRMmxKPf7WOXfgGWDnnRj0eikKb8teClcP90fzyPZr91FL4vwghVu3oex3PZahhbNOHoEt/fh7s8wHDsHiJx9Cs7BD7wf9r4czl4gzF+KrEE/8LrRvnSHuw+IDXMEHaCUyvmTem+BPkXGcRSICp1IbQ29n+IMpgHVKBBmRrFYiFSGYlGYFbcYA1SKNsSWZVk+A0xgaNdc1CIGuN71WpGG5tBhHGmg0rvno5Okodnnso0ASgsMGmJbZhXEA2lDqLIaUhpCnb2JlIbiLeOY0hB51mJKQ2wzSGsIMUCpXkApKUPIBA3U+gXUmjIUEYbr007jB9A8KZT/BzS/uufuw3D9MNQgUEHWRhg+n33/fPSPv//pz7AhgcoQT8+H4ZG73MZ8saUhmvRI7jKP+empf8SH4RGG4i3qcFCyOz1OPSr6tKmjji8D6TpUEadNFXfAGknzRBq2JX0FOAkZckZfUk5k8JIirlEplROp94FrNHzR92tvAhd9sBS5DdfLK9erfb7chlApYtfsAm3u19vwJaFiye6zC/wsga/bzeZoS+QhWM7lc6CAt20n1fo8DKEa29bErKGAZrtldxyGoGHDbNFOAO+HDvXm4hg6grFtxXA79FvDC7cVROPTX4cvMZhXjLGv8SFas277pTV7v7yfbQ4bX2tGNY9Kd6MhmsfJ7a1UoQWnb8DTjwjSDzHSj1nsYCnxaEmk4VniCnBiYFWmHvelHkimH5mmH+qmHzunH4ynH93//ssF+vWHYcW8/vgDsk2pVS+emuAAAAAASUVORK5CYII=',
19
+ },
20
+ text: {
21
+ type: String,
22
+ default: '保存图片',
23
+ },
24
+ fontSize: {
25
+ type: [Number, String],
26
+ default: 13,
27
+ },
28
+ color: {
29
+ type: String,
30
+ default: '',
31
+ },
32
+ space: {
33
+ type: [Number, String],
34
+ default: 4,
35
+ },
36
+ data: {
37
+ type: Object,
38
+ default: () => ({}),
39
+ },
40
+ custom: {
41
+ type: Function,
42
+ default: null,
43
+ },
44
+ customStyle: {
45
+ type: Object,
46
+ default: () => ({}),
47
+ },
48
+ },
49
+ computed: {
50
+ style({ size }) {
51
+ const value = uni.$uv.addUnit(size);
52
+ return {
53
+ width: value,
54
+ height: value,
55
+ };
56
+ },
57
+ textStyle({ fontSize, color, space }) {
58
+ return {
59
+ fontSize: uni.$uv.addUnit(fontSize),
60
+ marginTop: uni.$uv.addUnit(space),
61
+ color,
62
+ };
63
+ },
64
+ },
65
+ methods: {
66
+ click() {
67
+ if (typeof this.custom === 'function') {
68
+ this.custom(this.data);
69
+ } else {
70
+ this.$emit('confirm');
71
+ }
72
+ },
73
+ },
74
+ };
75
+ </script>