uview-ui-wjf 1.0.0
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/LICENSE +21 -0
- package/README.md +71 -0
- package/changelog.md +388 -0
- package/components/u--form/u--form.vue +92 -0
- package/components/u--image/u--image.vue +73 -0
- package/components/u--input/u--input.vue +115 -0
- package/components/u--text/u--text.vue +72 -0
- package/components/u--textarea/u--textarea.vue +85 -0
- package/components/u-action-sheet/props.js +54 -0
- package/components/u-action-sheet/u-action-sheet.vue +278 -0
- package/components/u-album/props.js +59 -0
- package/components/u-album/u-album.vue +259 -0
- package/components/u-alert/props.js +44 -0
- package/components/u-alert/u-alert.vue +243 -0
- package/components/u-avatar/props.js +78 -0
- package/components/u-avatar/u-avatar.vue +173 -0
- package/components/u-avatar-group/props.js +52 -0
- package/components/u-avatar-group/u-avatar-group.vue +103 -0
- package/components/u-back-top/props.js +54 -0
- package/components/u-back-top/u-back-top.vue +129 -0
- package/components/u-badge/props.js +72 -0
- package/components/u-badge/u-badge.vue +171 -0
- package/components/u-button/nvue.scss +46 -0
- package/components/u-button/props.js +161 -0
- package/components/u-button/u-button.vue +495 -0
- package/components/u-button/vue.scss +80 -0
- package/components/u-calendar/header.vue +99 -0
- package/components/u-calendar/month.vue +579 -0
- package/components/u-calendar/props.js +144 -0
- package/components/u-calendar/u-calendar.vue +384 -0
- package/components/u-calendar/util.js +85 -0
- package/components/u-car-keyboard/props.js +14 -0
- package/components/u-car-keyboard/u-car-keyboard.vue +311 -0
- package/components/u-cell/props.js +110 -0
- package/components/u-cell/u-cell.vue +229 -0
- package/components/u-cell-group/props.js +14 -0
- package/components/u-cell-group/u-cell-group.vue +61 -0
- package/components/u-checkbox/props.js +69 -0
- package/components/u-checkbox/u-checkbox.vue +344 -0
- package/components/u-checkbox-group/props.js +82 -0
- package/components/u-checkbox-group/u-checkbox-group.vue +103 -0
- package/components/u-circle-progress/props.js +8 -0
- package/components/u-circle-progress/u-circle-progress.vue +198 -0
- package/components/u-code/props.js +34 -0
- package/components/u-code/u-code.vue +129 -0
- package/components/u-code-input/props.js +79 -0
- package/components/u-code-input/u-code-input.vue +252 -0
- package/components/u-col/props.js +29 -0
- package/components/u-col/u-col.vue +162 -0
- package/components/u-collapse/props.js +19 -0
- package/components/u-collapse/u-collapse.vue +90 -0
- package/components/u-collapse-item/props.js +59 -0
- package/components/u-collapse-item/u-collapse-item.vue +225 -0
- package/components/u-column-notice/props.js +55 -0
- package/components/u-column-notice/u-column-notice.vue +160 -0
- package/components/u-count-down/props.js +24 -0
- package/components/u-count-down/u-count-down.vue +163 -0
- package/components/u-count-down/utils.js +62 -0
- package/components/u-count-to/props.js +59 -0
- package/components/u-count-to/u-count-to.vue +184 -0
- package/components/u-datetime-picker/props.js +120 -0
- package/components/u-datetime-picker/u-datetime-picker.vue +361 -0
- package/components/u-divider/props.js +44 -0
- package/components/u-divider/u-divider.vue +116 -0
- package/components/u-dropdown/props.js +65 -0
- package/components/u-dropdown/u-dropdown.vue +127 -0
- package/components/u-dropdown-item/props.js +36 -0
- package/components/u-dropdown-item/u-dropdown-item.vue +127 -0
- package/components/u-empty/props.js +59 -0
- package/components/u-empty/u-empty.vue +128 -0
- package/components/u-form/props.js +45 -0
- package/components/u-form/u-form.vue +214 -0
- package/components/u-form-item/props.js +48 -0
- package/components/u-form-item/u-form-item.vue +235 -0
- package/components/u-gap/props.js +24 -0
- package/components/u-gap/u-gap.vue +38 -0
- package/components/u-grid/props.js +19 -0
- package/components/u-grid/u-grid.vue +97 -0
- package/components/u-grid-item/props.js +14 -0
- package/components/u-grid-item/u-grid-item.vue +209 -0
- package/components/u-icon/icons.js +214 -0
- package/components/u-icon/props.js +89 -0
- package/components/u-icon/u-icon.vue +237 -0
- package/components/u-image/props.js +84 -0
- package/components/u-image/u-image.vue +232 -0
- package/components/u-index-anchor/props.js +29 -0
- package/components/u-index-anchor/u-index-anchor.vue +91 -0
- package/components/u-index-item/props.js +5 -0
- package/components/u-index-item/u-index-item.vue +87 -0
- package/components/u-index-list/props.js +29 -0
- package/components/u-index-list/u-index-list.vue +440 -0
- package/components/u-input/props.js +187 -0
- package/components/u-input/u-input.vue +369 -0
- package/components/u-keyboard/props.js +84 -0
- package/components/u-keyboard/u-keyboard.vue +164 -0
- package/components/u-line/props.js +33 -0
- package/components/u-line/u-line.vue +62 -0
- package/components/u-line-progress/props.js +28 -0
- package/components/u-line-progress/u-line-progress.vue +144 -0
- package/components/u-link/props.js +39 -0
- package/components/u-link/u-link.vue +83 -0
- package/components/u-list/props.js +76 -0
- package/components/u-list/u-list.vue +157 -0
- package/components/u-list-item/props.js +9 -0
- package/components/u-list-item/u-list-item.vue +116 -0
- package/components/u-loading-icon/props.js +59 -0
- package/components/u-loading-icon/u-loading-icon.vue +343 -0
- package/components/u-loading-page/props.js +49 -0
- package/components/u-loading-page/u-loading-page.vue +115 -0
- package/components/u-loadmore/props.js +94 -0
- package/components/u-loadmore/u-loadmore.vue +150 -0
- package/components/u-modal/props.js +89 -0
- package/components/u-modal/u-modal.vue +228 -0
- package/components/u-navbar/props.js +84 -0
- package/components/u-navbar/u-navbar.vue +186 -0
- package/components/u-no-network/props.js +19 -0
- package/components/u-no-network/u-no-network.vue +220 -0
- package/components/u-notice-bar/props.js +70 -0
- package/components/u-notice-bar/u-notice-bar.vue +101 -0
- package/components/u-notify/props.js +49 -0
- package/components/u-notify/u-notify.vue +211 -0
- package/components/u-number-box/props.js +109 -0
- package/components/u-number-box/u-number-box.vue +416 -0
- package/components/u-number-keyboard/props.js +19 -0
- package/components/u-number-keyboard/u-number-keyboard.vue +196 -0
- package/components/u-overlay/props.js +24 -0
- package/components/u-overlay/u-overlay.vue +68 -0
- package/components/u-parse/node/node.vue +499 -0
- package/components/u-parse/parser.js +1075 -0
- package/components/u-parse/props.js +45 -0
- package/components/u-parse/u-parse.vue +366 -0
- package/components/u-picker/props.js +79 -0
- package/components/u-picker/u-picker.vue +286 -0
- package/components/u-picker-column/props.js +5 -0
- package/components/u-picker-column/u-picker-column.vue +27 -0
- package/components/u-popup/props.js +79 -0
- package/components/u-popup/u-popup.vue +304 -0
- package/components/u-radio/props.js +64 -0
- package/components/u-radio/u-radio.vue +339 -0
- package/components/u-radio-group/props.js +85 -0
- package/components/u-radio-group/u-radio-group.vue +108 -0
- package/components/u-rate/props.js +69 -0
- package/components/u-rate/u-rate.vue +306 -0
- package/components/u-read-more/props.js +61 -0
- package/components/u-read-more/u-read-more.vue +157 -0
- package/components/u-row/props.js +19 -0
- package/components/u-row/u-row.vue +93 -0
- package/components/u-row-notice/props.js +39 -0
- package/components/u-row-notice/u-row-notice.vue +330 -0
- package/components/u-safe-bottom/props.js +5 -0
- package/components/u-safe-bottom/u-safe-bottom.vue +56 -0
- package/components/u-scroll-list/nvue.js +28 -0
- package/components/u-scroll-list/other.js +0 -0
- package/components/u-scroll-list/props.js +34 -0
- package/components/u-scroll-list/scrollWxs.wxs +50 -0
- package/components/u-scroll-list/u-scroll-list.vue +224 -0
- package/components/u-search/props.js +118 -0
- package/components/u-search/u-search.vue +303 -0
- package/components/u-skeleton/props.js +59 -0
- package/components/u-skeleton/u-skeleton.vue +244 -0
- package/components/u-slider/mpother.js +113 -0
- package/components/u-slider/mpwxs.js +42 -0
- package/components/u-slider/mpwxs.wxs +121 -0
- package/components/u-slider/nvue - /345/211/257/346/234/254.js" +180 -0
- package/components/u-slider/nvue.js +193 -0
- package/components/u-slider/props.js +54 -0
- package/components/u-slider/u-slider.vue +55 -0
- package/components/u-status-bar/props.js +8 -0
- package/components/u-status-bar/u-status-bar.vue +46 -0
- package/components/u-steps/props.js +39 -0
- package/components/u-steps/u-steps.vue +80 -0
- package/components/u-steps-item/props.js +24 -0
- package/components/u-steps-item/u-steps-item.vue +316 -0
- package/components/u-sticky/props.js +40 -0
- package/components/u-sticky/u-sticky.vue +212 -0
- package/components/u-subsection/props.js +49 -0
- package/components/u-subsection/u-subsection.vue +299 -0
- package/components/u-swipe-action/props.js +9 -0
- package/components/u-swipe-action/u-swipe-action.vue +67 -0
- package/components/u-swipe-action-item/index - backup.wxs +256 -0
- package/components/u-swipe-action-item/index.wxs +225 -0
- package/components/u-swipe-action-item/nvue - backup.js +270 -0
- package/components/u-swipe-action-item/nvue.js +174 -0
- package/components/u-swipe-action-item/props.js +41 -0
- package/components/u-swipe-action-item/u-swipe-action-item.vue +190 -0
- package/components/u-swipe-action-item/wxs.js +15 -0
- package/components/u-swiper/props.js +125 -0
- package/components/u-swiper/u-swiper.vue +255 -0
- package/components/u-swiper-indicator/props.js +29 -0
- package/components/u-swiper-indicator/u-swiper-indicator.vue +110 -0
- package/components/u-switch/props.js +54 -0
- package/components/u-switch/u-switch.vue +177 -0
- package/components/u-tabbar/props.js +44 -0
- package/components/u-tabbar/u-tabbar.vue +141 -0
- package/components/u-tabbar-item/props.js +35 -0
- package/components/u-tabbar-item/u-tabbar-item.vue +142 -0
- package/components/u-table/props.js +5 -0
- package/components/u-table/u-table.vue +29 -0
- package/components/u-tabs/props.js +64 -0
- package/components/u-tabs/u-tabs.vue +363 -0
- package/components/u-tabs-item/props.js +5 -0
- package/components/u-tabs-item/u-tabs-item.vue +29 -0
- package/components/u-tag/props.js +84 -0
- package/components/u-tag/u-tag.vue +358 -0
- package/components/u-td/props.js +5 -0
- package/components/u-td/u-td.vue +31 -0
- package/components/u-text/props.js +110 -0
- package/components/u-text/u-text.vue +223 -0
- package/components/u-text/value.js +85 -0
- package/components/u-textarea/props.js +119 -0
- package/components/u-textarea/u-textarea.vue +239 -0
- package/components/u-toast/u-toast.vue +291 -0
- package/components/u-toolbar/props.js +34 -0
- package/components/u-toolbar/u-toolbar.vue +102 -0
- package/components/u-tooltip/clipboard.min.js +58 -0
- package/components/u-tooltip/props.js +59 -0
- package/components/u-tooltip/u-tooltip.vue +366 -0
- package/components/u-tr/props.js +5 -0
- package/components/u-tr/u-tr.vue +31 -0
- package/components/u-transition/nvue.ani-map.js +68 -0
- package/components/u-transition/props.js +24 -0
- package/components/u-transition/transition.js +157 -0
- package/components/u-transition/u-transition.vue +92 -0
- package/components/u-transition/vue.ani-style.scss +113 -0
- package/components/u-upload/mixin.js +21 -0
- package/components/u-upload/props.js +124 -0
- package/components/u-upload/u-upload.vue +566 -0
- package/components/u-upload/utils.js +151 -0
- package/components/uview-ui/uview-ui.vue +15 -0
- package/index.js +79 -0
- package/index.scss +23 -0
- package/libs/config/color.js +17 -0
- package/libs/config/config.js +34 -0
- package/libs/config/props/actionSheet.js +25 -0
- package/libs/config/props/album.js +25 -0
- package/libs/config/props/alert.js +22 -0
- package/libs/config/props/avatar.js +28 -0
- package/libs/config/props/avatarGroup.js +23 -0
- package/libs/config/props/backtop.js +27 -0
- package/libs/config/props/badge.js +27 -0
- package/libs/config/props/button.js +42 -0
- package/libs/config/props/calendar.js +42 -0
- package/libs/config/props/carKeyboard.js +15 -0
- package/libs/config/props/cell.js +35 -0
- package/libs/config/props/cellGroup.js +17 -0
- package/libs/config/props/checkbox.js +27 -0
- package/libs/config/props/checkboxGroup.js +29 -0
- package/libs/config/props/circleProgress.js +15 -0
- package/libs/config/props/code.js +21 -0
- package/libs/config/props/codeInput.js +29 -0
- package/libs/config/props/col.js +19 -0
- package/libs/config/props/collapse.js +17 -0
- package/libs/config/props/collapseItem.js +25 -0
- package/libs/config/props/columnNotice.js +24 -0
- package/libs/config/props/countDown.js +18 -0
- package/libs/config/props/countTo.js +25 -0
- package/libs/config/props/datetimePicker.js +37 -0
- package/libs/config/props/divider.js +23 -0
- package/libs/config/props/empty.js +26 -0
- package/libs/config/props/form.js +22 -0
- package/libs/config/props/formItem.js +23 -0
- package/libs/config/props/gap.js +19 -0
- package/libs/config/props/grid.js +17 -0
- package/libs/config/props/gridItem.js +16 -0
- package/libs/config/props/icon.js +36 -0
- package/libs/config/props/image.js +30 -0
- package/libs/config/props/indexAnchor.js +19 -0
- package/libs/config/props/indexList.js +19 -0
- package/libs/config/props/input.js +48 -0
- package/libs/config/props/keyboard.js +30 -0
- package/libs/config/props/line.js +20 -0
- package/libs/config/props/lineProgress.js +19 -0
- package/libs/config/props/link.js +26 -0
- package/libs/config/props/list.js +28 -0
- package/libs/config/props/listItem.js +15 -0
- package/libs/config/props/loadingIcon.js +30 -0
- package/libs/config/props/loadingPage.js +23 -0
- package/libs/config/props/loadmore.js +32 -0
- package/libs/config/props/modal.js +31 -0
- package/libs/config/props/navbar.js +32 -0
- package/libs/config/props/noNetwork.js +18 -0
- package/libs/config/props/noticeBar.js +27 -0
- package/libs/config/props/notify.js +22 -0
- package/libs/config/props/numberBox.js +35 -0
- package/libs/config/props/numberKeyboard.js +17 -0
- package/libs/config/props/overlay.js +18 -0
- package/libs/config/props/parse.js +22 -0
- package/libs/config/props/picker.js +29 -0
- package/libs/config/props/popup.js +29 -0
- package/libs/config/props/radio.js +27 -0
- package/libs/config/props/radioGroup.js +30 -0
- package/libs/config/props/rate.js +26 -0
- package/libs/config/props/readMore.js +22 -0
- package/libs/config/props/row.js +17 -0
- package/libs/config/props/rowNotice.js +21 -0
- package/libs/config/props/scrollList.js +20 -0
- package/libs/config/props/search.js +37 -0
- package/libs/config/props/section.js +24 -0
- package/libs/config/props/skeleton.js +25 -0
- package/libs/config/props/slider.js +25 -0
- package/libs/config/props/statusBar.js +15 -0
- package/libs/config/props/steps.js +21 -0
- package/libs/config/props/stepsItem.js +18 -0
- package/libs/config/props/sticky.js +20 -0
- package/libs/config/props/subsection.js +23 -0
- package/libs/config/props/swipeAction.js +15 -0
- package/libs/config/props/swipeActionItem.js +21 -0
- package/libs/config/props/swiper.js +39 -0
- package/libs/config/props/swipterIndicator.js +19 -0
- package/libs/config/props/switch.js +24 -0
- package/libs/config/props/tabbar.js +22 -0
- package/libs/config/props/tabbarItem.js +20 -0
- package/libs/config/props/tabs.js +32 -0
- package/libs/config/props/tag.js +29 -0
- package/libs/config/props/text.js +38 -0
- package/libs/config/props/textarea.js +36 -0
- package/libs/config/props/toast.js +30 -0
- package/libs/config/props/toolbar.js +21 -0
- package/libs/config/props/tooltip.js +25 -0
- package/libs/config/props/transition.js +18 -0
- package/libs/config/props/upload.js +36 -0
- package/libs/config/props.js +190 -0
- package/libs/config/zIndex.js +20 -0
- package/libs/css/color.scss +155 -0
- package/libs/css/common.scss +97 -0
- package/libs/css/components.scss +15 -0
- package/libs/css/flex.scss +257 -0
- package/libs/css/h5.scss +0 -0
- package/libs/css/mixin.scss +8 -0
- package/libs/css/mp.scss +0 -0
- package/libs/css/nvue.scss +0 -0
- package/libs/css/vue.scss +27 -0
- package/libs/function/colorGradient.js +134 -0
- package/libs/function/debounce.js +29 -0
- package/libs/function/digit.js +167 -0
- package/libs/function/index.js +731 -0
- package/libs/function/platform.js +75 -0
- package/libs/function/test.js +288 -0
- package/libs/function/throttle.js +30 -0
- package/libs/luch-request/adapters/index.js +97 -0
- package/libs/luch-request/core/InterceptorManager.js +50 -0
- package/libs/luch-request/core/Request.js +198 -0
- package/libs/luch-request/core/buildFullPath.js +20 -0
- package/libs/luch-request/core/defaults.js +29 -0
- package/libs/luch-request/core/dispatchRequest.js +3 -0
- package/libs/luch-request/core/mergeConfig.js +103 -0
- package/libs/luch-request/core/settle.js +16 -0
- package/libs/luch-request/helpers/buildURL.js +69 -0
- package/libs/luch-request/helpers/combineURLs.js +14 -0
- package/libs/luch-request/helpers/isAbsoluteURL.js +14 -0
- package/libs/luch-request/index.d.ts +116 -0
- package/libs/luch-request/index.js +3 -0
- package/libs/luch-request/utils/clone.js +264 -0
- package/libs/luch-request/utils.js +131 -0
- package/libs/mixin/button.js +13 -0
- package/libs/mixin/mixin.js +160 -0
- package/libs/mixin/mpMixin.js +8 -0
- package/libs/mixin/mpShare.js +13 -0
- package/libs/mixin/openType.js +25 -0
- package/libs/mixin/style.js +228 -0
- package/libs/mixin/touch.js +59 -0
- package/libs/util/async-validator.js +1343 -0
- package/libs/util/calendar.js +546 -0
- package/libs/util/dayjs.js +308 -0
- package/libs/util/emitter.js +51 -0
- package/libs/util/route.js +124 -0
- package/package.json +83 -0
- package/theme.scss +44 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-form">
|
|
3
|
+
<slot />
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import props from "./props.js";
|
|
9
|
+
import Schema from "../../libs/util/async-validator";
|
|
10
|
+
// 去除警告信息
|
|
11
|
+
Schema.warning = function() {};
|
|
12
|
+
/**
|
|
13
|
+
* Form 表单
|
|
14
|
+
* @description 此组件一般用于表单场景,可以配置Input输入框,Select弹出框,进行表单验证等。
|
|
15
|
+
* @tutorial https://www.uviewui.com/components/form.html
|
|
16
|
+
* @property {Object} model 当前form的需要验证字段的集合
|
|
17
|
+
* @property {Object | Function | Array} rules 验证规则
|
|
18
|
+
* @property {String} errorType 错误的提示方式,见上方说明 ( 默认 message )
|
|
19
|
+
* @property {Boolean} borderBottom 是否显示表单域的下划线边框 ( 默认 true )
|
|
20
|
+
* @property {String} labelPosition 表单域提示文字的位置,left-左侧,top-上方 ( 默认 'left' )
|
|
21
|
+
* @property {String | Number} labelWidth 提示文字的宽度,单位px ( 默认 45 )
|
|
22
|
+
* @property {String} labelAlign lable字体的对齐方式 ( 默认 ‘left' )
|
|
23
|
+
* @property {Object} labelStyle lable的样式,对象形式
|
|
24
|
+
* @example <u--formlabelPosition="left" :model="model1" :rules="rules" ref="form1"></u--form>
|
|
25
|
+
*/
|
|
26
|
+
export default {
|
|
27
|
+
name: "u-form",
|
|
28
|
+
mixins: [uni.$u.mpMixin, uni.$u.mixin, props],
|
|
29
|
+
provide() {
|
|
30
|
+
return {
|
|
31
|
+
uForm: this,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
data() {
|
|
35
|
+
return {
|
|
36
|
+
formRules: {},
|
|
37
|
+
// 规则校验器
|
|
38
|
+
validator: {},
|
|
39
|
+
// 原始的model快照,用于resetFields方法重置表单时使用
|
|
40
|
+
originalModel: null,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
watch: {
|
|
44
|
+
// 监听规则的变化
|
|
45
|
+
rules: {
|
|
46
|
+
immediate: true,
|
|
47
|
+
handler(n) {
|
|
48
|
+
this.setRules(n);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
// 监听属性的变化,通知子组件u-form-item重新获取信息
|
|
52
|
+
propsChange(n) {
|
|
53
|
+
if (this.children?.length) {
|
|
54
|
+
this.children.map((child) => {
|
|
55
|
+
// 判断子组件(u-form-item)如果有updateParentData方法的话,就就执行(执行的结果是子组件重新从父组件拉取了最新的值)
|
|
56
|
+
typeof child.updateParentData == "function" &&
|
|
57
|
+
child.updateParentData();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
// 监听model的初始值作为重置表单的快照
|
|
62
|
+
model: {
|
|
63
|
+
immediate: true,
|
|
64
|
+
handler(n) {
|
|
65
|
+
if (!this.originalModel) {
|
|
66
|
+
this.originalModel = uni.$u.deepClone(n);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
computed: {
|
|
72
|
+
propsChange() {
|
|
73
|
+
return [
|
|
74
|
+
this.errorType,
|
|
75
|
+
this.borderBottom,
|
|
76
|
+
this.labelPosition,
|
|
77
|
+
this.labelWidth,
|
|
78
|
+
this.labelAlign,
|
|
79
|
+
this.labelStyle,
|
|
80
|
+
];
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
created() {
|
|
84
|
+
// 存储当前form下的所有u-form-item的实例
|
|
85
|
+
// 不能定义在data中,否则微信小程序会造成循环引用而报错
|
|
86
|
+
this.children = [];
|
|
87
|
+
},
|
|
88
|
+
methods: {
|
|
89
|
+
// 手动设置校验的规则,如果规则中有函数的话,微信小程序中会过滤掉,所以只能手动调用设置规则
|
|
90
|
+
setRules(rules) {
|
|
91
|
+
// 判断是否有规则
|
|
92
|
+
if (Object.keys(rules).length === 0) return;
|
|
93
|
+
if (process.env.NODE_ENV === 'development' && Object.keys(this.model).length === 0) {
|
|
94
|
+
uni.$u.error('设置rules,model必须设置!如果已经设置,请刷新页面。');
|
|
95
|
+
return;
|
|
96
|
+
};
|
|
97
|
+
this.formRules = rules;
|
|
98
|
+
// 重新将规则赋予Validator
|
|
99
|
+
this.validator = new Schema(rules);
|
|
100
|
+
},
|
|
101
|
+
// 清空所有u-form-item组件的内容,本质上是调用了u-form-item组件中的resetField()方法
|
|
102
|
+
resetFields() {
|
|
103
|
+
this.resetModel();
|
|
104
|
+
},
|
|
105
|
+
// 重置model为初始值的快照
|
|
106
|
+
resetModel(obj) {
|
|
107
|
+
// 历遍所有u-form-item,根据其prop属性,还原model的原始快照
|
|
108
|
+
this.children.map((child) => {
|
|
109
|
+
const prop = child?.prop;
|
|
110
|
+
const value = uni.$u.getProperty(this.originalModel, prop);
|
|
111
|
+
uni.$u.setProperty(this.model, prop, value);
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
// 清空校验结果
|
|
115
|
+
clearValidate(props) {
|
|
116
|
+
props = [].concat(props);
|
|
117
|
+
this.children.map((child) => {
|
|
118
|
+
// 如果u-form-item的prop在props数组中,则清除对应的校验结果信息
|
|
119
|
+
if (props[0] === undefined || props.includes(child.prop)) {
|
|
120
|
+
child.message = null;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
// 对部分表单字段进行校验
|
|
125
|
+
async validateField(value, callback, event = null) {
|
|
126
|
+
// $nextTick是必须的,否则model的变更,可能会延后于此方法的执行
|
|
127
|
+
this.$nextTick(() => {
|
|
128
|
+
// 校验错误信息,返回给回调方法,用于存放所有form-item的错误信息
|
|
129
|
+
const errorsRes = [];
|
|
130
|
+
// 如果为字符串,转为数组
|
|
131
|
+
value = [].concat(value);
|
|
132
|
+
// 历遍children所有子form-item
|
|
133
|
+
this.children.map((child) => {
|
|
134
|
+
// 用于存放form-item的错误信息
|
|
135
|
+
const childErrors = [];
|
|
136
|
+
if (value.includes(child.prop)) {
|
|
137
|
+
// 获取对应的属性,通过类似'a.b.c'的形式
|
|
138
|
+
const propertyVal = uni.$u.getProperty(
|
|
139
|
+
this.model,
|
|
140
|
+
child.prop
|
|
141
|
+
);
|
|
142
|
+
// 属性链数组
|
|
143
|
+
const propertyChain = child.prop.split(".");
|
|
144
|
+
const propertyName =
|
|
145
|
+
propertyChain[propertyChain.length - 1];
|
|
146
|
+
|
|
147
|
+
const rule = this.formRules[child.prop];
|
|
148
|
+
// 如果不存在对应的规则,直接返回,否则校验器会报错
|
|
149
|
+
if (!rule) return;
|
|
150
|
+
// rule规则可为数组形式,也可为对象形式,此处拼接成为数组
|
|
151
|
+
const rules = [].concat(rule);
|
|
152
|
+
|
|
153
|
+
// 对rules数组进行校验
|
|
154
|
+
for (let i = 0; i < rules.length; i++) {
|
|
155
|
+
const ruleItem = rules[i];
|
|
156
|
+
// 将u-form-item的触发器转为数组形式
|
|
157
|
+
const trigger = [].concat(ruleItem?.trigger);
|
|
158
|
+
// 如果是有传入触发事件,但是此form-item却没有配置此触发器的话,不执行校验操作
|
|
159
|
+
if (event && !trigger.includes(event)) continue;
|
|
160
|
+
// 实例化校验对象,传入构造规则
|
|
161
|
+
const validator = new Schema({
|
|
162
|
+
[propertyName]: ruleItem,
|
|
163
|
+
});
|
|
164
|
+
validator.validate({
|
|
165
|
+
[propertyName]: propertyVal,
|
|
166
|
+
},
|
|
167
|
+
(errors, fields) => {
|
|
168
|
+
if (uni.$u.test.array(errors)) {
|
|
169
|
+
errorsRes.push(...errors);
|
|
170
|
+
childErrors.push(...errors);
|
|
171
|
+
}
|
|
172
|
+
child.message =
|
|
173
|
+
childErrors[0]?.message ?? null;
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
// 执行回调函数
|
|
180
|
+
typeof callback === "function" && callback(errorsRes);
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
// 校验全部数据
|
|
184
|
+
validate(callback) {
|
|
185
|
+
// 开发环境才提示,生产环境不会提示
|
|
186
|
+
if (process.env.NODE_ENV === 'development' && Object.keys(this.formRules).length === 0) {
|
|
187
|
+
uni.$u.error('未设置rules,请看文档说明!如果已经设置,请刷新页面。');
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
return new Promise((resolve, reject) => {
|
|
191
|
+
// $nextTick是必须的,否则model的变更,可能会延后于validate方法
|
|
192
|
+
this.$nextTick(() => {
|
|
193
|
+
// 获取所有form-item的prop,交给validateField方法进行校验
|
|
194
|
+
const formItemProps = this.children.map(
|
|
195
|
+
(item) => item.prop
|
|
196
|
+
);
|
|
197
|
+
this.validateField(formItemProps, (errors) => {
|
|
198
|
+
if(errors.length) {
|
|
199
|
+
// 如果错误提示方式为toast,则进行提示
|
|
200
|
+
this.errorType === 'toast' && uni.$u.toast(errors[0].message)
|
|
201
|
+
reject(errors)
|
|
202
|
+
} else {
|
|
203
|
+
resolve(true)
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
</script>
|
|
212
|
+
|
|
213
|
+
<style lang="scss" scoped>
|
|
214
|
+
</style>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
props: {
|
|
3
|
+
// input的label提示语
|
|
4
|
+
label: {
|
|
5
|
+
type: String,
|
|
6
|
+
default: uni.$u.props.formItem.label
|
|
7
|
+
},
|
|
8
|
+
// 绑定的值
|
|
9
|
+
prop: {
|
|
10
|
+
type: String,
|
|
11
|
+
default: uni.$u.props.formItem.prop
|
|
12
|
+
},
|
|
13
|
+
// 是否显示表单域的下划线边框
|
|
14
|
+
borderBottom: {
|
|
15
|
+
type: [String, Boolean],
|
|
16
|
+
default: uni.$u.props.formItem.borderBottom
|
|
17
|
+
},
|
|
18
|
+
// label的位置,left-左边,top-上边
|
|
19
|
+
labelPosition: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: uni.$u.props.formItem.labelPosition
|
|
22
|
+
},
|
|
23
|
+
// label的宽度,单位px
|
|
24
|
+
labelWidth: {
|
|
25
|
+
type: [String, Number],
|
|
26
|
+
default: uni.$u.props.formItem.labelWidth
|
|
27
|
+
},
|
|
28
|
+
// 右侧图标
|
|
29
|
+
rightIcon: {
|
|
30
|
+
type: String,
|
|
31
|
+
default: uni.$u.props.formItem.rightIcon
|
|
32
|
+
},
|
|
33
|
+
// 左侧图标
|
|
34
|
+
leftIcon: {
|
|
35
|
+
type: String,
|
|
36
|
+
default: uni.$u.props.formItem.leftIcon
|
|
37
|
+
},
|
|
38
|
+
// 是否显示左边的必填星号,只作显示用,具体校验必填的逻辑,请在rules中配置
|
|
39
|
+
required: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
default: uni.$u.props.formItem.required
|
|
42
|
+
},
|
|
43
|
+
leftIconStyle: {
|
|
44
|
+
type: [String, Object],
|
|
45
|
+
default: uni.$u.props.formItem.leftIconStyle,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-form-item">
|
|
3
|
+
<view
|
|
4
|
+
class="u-form-item__body"
|
|
5
|
+
@tap="clickHandler"
|
|
6
|
+
:style="[$u.addStyle(customStyle), {
|
|
7
|
+
flexDirection: (labelPosition || parentData.labelPosition) === 'left' ? 'row' : 'column'
|
|
8
|
+
}]"
|
|
9
|
+
>
|
|
10
|
+
<!-- 微信小程序中,将一个参数设置空字符串,结果会变成字符串"true" -->
|
|
11
|
+
<slot name="label">
|
|
12
|
+
<!-- {{required}} -->
|
|
13
|
+
<view
|
|
14
|
+
class="u-form-item__body__left"
|
|
15
|
+
v-if="required || leftIcon || label"
|
|
16
|
+
:style="{
|
|
17
|
+
width: $u.addUnit(labelWidth || parentData.labelWidth),
|
|
18
|
+
marginBottom: parentData.labelPosition === 'left' ? 0 : '5px',
|
|
19
|
+
}"
|
|
20
|
+
>
|
|
21
|
+
<!-- 为了块对齐 -->
|
|
22
|
+
<view class="u-form-item__body__left__content">
|
|
23
|
+
<!-- nvue不支持伪元素before -->
|
|
24
|
+
<text
|
|
25
|
+
v-if="required"
|
|
26
|
+
class="u-form-item__body__left__content__required"
|
|
27
|
+
>*</text>
|
|
28
|
+
<view
|
|
29
|
+
class="u-form-item__body__left__content__icon"
|
|
30
|
+
v-if="leftIcon"
|
|
31
|
+
>
|
|
32
|
+
<u-icon
|
|
33
|
+
:name="leftIcon"
|
|
34
|
+
:custom-style="leftIconStyle"
|
|
35
|
+
></u-icon>
|
|
36
|
+
</view>
|
|
37
|
+
<text
|
|
38
|
+
class="u-form-item__body__left__content__label"
|
|
39
|
+
:style="[parentData.labelStyle, {
|
|
40
|
+
justifyContent: parentData.labelAlign === 'left' ? 'flex-start' : parentData.labelAlign === 'center' ? 'center' : 'flex-end'
|
|
41
|
+
}]"
|
|
42
|
+
>{{ label }}</text>
|
|
43
|
+
</view>
|
|
44
|
+
</view>
|
|
45
|
+
</slot>
|
|
46
|
+
<view class="u-form-item__body__right">
|
|
47
|
+
<view class="u-form-item__body__right__content">
|
|
48
|
+
<view class="u-form-item__body__right__content__slot">
|
|
49
|
+
<slot />
|
|
50
|
+
</view>
|
|
51
|
+
<view
|
|
52
|
+
class="item__body__right__content__icon"
|
|
53
|
+
v-if="$slots.right"
|
|
54
|
+
>
|
|
55
|
+
<slot name="right" />
|
|
56
|
+
</view>
|
|
57
|
+
</view>
|
|
58
|
+
</view>
|
|
59
|
+
</view>
|
|
60
|
+
<slot name="error" v-bind:message="message">
|
|
61
|
+
<text
|
|
62
|
+
v-if="!!message && parentData.errorType === 'message'"
|
|
63
|
+
class="u-form-item__body__right__message"
|
|
64
|
+
:style="{
|
|
65
|
+
marginLeft: $u.addUnit(parentData.labelPosition === 'top' ? 0 : (labelWidth || parentData.labelWidth))
|
|
66
|
+
}"
|
|
67
|
+
>{{ message }}</text>
|
|
68
|
+
</slot>
|
|
69
|
+
<u-line
|
|
70
|
+
v-if="borderBottom"
|
|
71
|
+
:color="message && parentData.errorType === 'border-bottom' ? $u.color.error : propsLine.color"
|
|
72
|
+
:customStyle="`margin-top: ${message && parentData.errorType === 'message' ? '5px' : 0}`"
|
|
73
|
+
></u-line>
|
|
74
|
+
</view>
|
|
75
|
+
</template>
|
|
76
|
+
|
|
77
|
+
<script>
|
|
78
|
+
import props from './props.js';
|
|
79
|
+
/**
|
|
80
|
+
* Form 表单
|
|
81
|
+
* @description 此组件一般用于表单场景,可以配置Input输入框,Select弹出框,进行表单验证等。
|
|
82
|
+
* @tutorial https://www.uviewui.com/components/form.html
|
|
83
|
+
* @property {String} label input的label提示语
|
|
84
|
+
* @property {String} prop 绑定的值
|
|
85
|
+
* @property {String | Boolean} borderBottom 是否显示表单域的下划线边框
|
|
86
|
+
* @property {String | Number} labelWidth label的宽度,单位px
|
|
87
|
+
* @property {String} rightIcon 右侧图标
|
|
88
|
+
* @property {String} leftIcon 左侧图标
|
|
89
|
+
* @property {String | Object} leftIconStyle 左侧图标的样式
|
|
90
|
+
* @property {Boolean} required 是否显示左边的必填星号,只作显示用,具体校验必填的逻辑,请在rules中配置 (默认 false )
|
|
91
|
+
*
|
|
92
|
+
* @example <u-form-item label="姓名" prop="userInfo.name" borderBottom ref="item1"></u-form-item>
|
|
93
|
+
*/
|
|
94
|
+
export default {
|
|
95
|
+
name: 'u-form-item',
|
|
96
|
+
mixins: [uni.$u.mpMixin, uni.$u.mixin, props],
|
|
97
|
+
data() {
|
|
98
|
+
return {
|
|
99
|
+
// 错误提示语
|
|
100
|
+
message: '',
|
|
101
|
+
parentData: {
|
|
102
|
+
// 提示文本的位置
|
|
103
|
+
labelPosition: 'left',
|
|
104
|
+
// 提示文本对齐方式
|
|
105
|
+
labelAlign: 'left',
|
|
106
|
+
// 提示文本的样式
|
|
107
|
+
labelStyle: {},
|
|
108
|
+
// 提示文本的宽度
|
|
109
|
+
labelWidth: 45,
|
|
110
|
+
// 错误提示方式
|
|
111
|
+
errorType: 'message'
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
// 组件创建完成时,将当前实例保存到u-form中
|
|
116
|
+
computed: {
|
|
117
|
+
propsLine() {
|
|
118
|
+
return uni.$u.props.line
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
mounted() {
|
|
122
|
+
this.init()
|
|
123
|
+
},
|
|
124
|
+
methods: {
|
|
125
|
+
init() {
|
|
126
|
+
// 父组件的实例
|
|
127
|
+
this.updateParentData()
|
|
128
|
+
if (!this.parent) {
|
|
129
|
+
uni.$u.error('u-form-item需要结合u-form组件使用')
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
// 获取父组件的参数
|
|
133
|
+
updateParentData() {
|
|
134
|
+
// 此方法写在mixin中
|
|
135
|
+
this.getParentData('u-form');
|
|
136
|
+
},
|
|
137
|
+
// 移除u-form-item的校验结果
|
|
138
|
+
clearValidate() {
|
|
139
|
+
this.message = null
|
|
140
|
+
},
|
|
141
|
+
// 清空当前的组件的校验结果,并重置为初始值
|
|
142
|
+
resetField() {
|
|
143
|
+
// 找到原始值
|
|
144
|
+
const value = uni.$u.getProperty(this.parent.originalModel, this.prop)
|
|
145
|
+
// 将u-form的model的prop属性链还原原始值
|
|
146
|
+
uni.$u.setProperty(this.parent.model, this.prop, value)
|
|
147
|
+
// 移除校验结果
|
|
148
|
+
this.message = null
|
|
149
|
+
},
|
|
150
|
+
// 点击组件
|
|
151
|
+
clickHandler() {
|
|
152
|
+
this.$emit('click')
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
}
|
|
156
|
+
</script>
|
|
157
|
+
|
|
158
|
+
<style lang="scss" scoped>
|
|
159
|
+
@import "../../libs/css/components.scss";
|
|
160
|
+
|
|
161
|
+
.u-form-item {
|
|
162
|
+
@include flex(column);
|
|
163
|
+
font-size: 14px;
|
|
164
|
+
color: $u-main-color;
|
|
165
|
+
|
|
166
|
+
&__body {
|
|
167
|
+
@include flex;
|
|
168
|
+
padding: 10px 0;
|
|
169
|
+
|
|
170
|
+
&__left {
|
|
171
|
+
@include flex;
|
|
172
|
+
align-items: center;
|
|
173
|
+
|
|
174
|
+
&__content {
|
|
175
|
+
position: relative;
|
|
176
|
+
@include flex;
|
|
177
|
+
align-items: center;
|
|
178
|
+
padding-right: 10rpx;
|
|
179
|
+
flex: 1;
|
|
180
|
+
|
|
181
|
+
&__icon {
|
|
182
|
+
margin-right: 8rpx;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
&__required {
|
|
186
|
+
position: absolute;
|
|
187
|
+
left: -9px;
|
|
188
|
+
color: $u-error;
|
|
189
|
+
line-height: 20px;
|
|
190
|
+
font-size: 20px;
|
|
191
|
+
top: 3px;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
&__label {
|
|
195
|
+
@include flex;
|
|
196
|
+
align-items: center;
|
|
197
|
+
flex: 1;
|
|
198
|
+
color: $u-main-color;
|
|
199
|
+
font-size: 15px;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
&__right {
|
|
205
|
+
flex: 1;
|
|
206
|
+
|
|
207
|
+
&__content {
|
|
208
|
+
@include flex;
|
|
209
|
+
align-items: center;
|
|
210
|
+
flex: 1;
|
|
211
|
+
|
|
212
|
+
&__slot {
|
|
213
|
+
flex: 1;
|
|
214
|
+
/* #ifndef MP */
|
|
215
|
+
@include flex;
|
|
216
|
+
align-items: center;
|
|
217
|
+
/* #endif */
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
&__icon {
|
|
221
|
+
margin-left: 10rpx;
|
|
222
|
+
color: $u-light-color;
|
|
223
|
+
font-size: 30rpx;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
&__message {
|
|
228
|
+
font-size: 12px;
|
|
229
|
+
line-height: 12px;
|
|
230
|
+
color: $u-error;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
</style>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
props: {
|
|
3
|
+
// 背景颜色(默认transparent)
|
|
4
|
+
bgColor: {
|
|
5
|
+
type: String,
|
|
6
|
+
default: uni.$u.props.gap.bgColor
|
|
7
|
+
},
|
|
8
|
+
// 分割槽高度,单位px(默认30)
|
|
9
|
+
height: {
|
|
10
|
+
type: [String, Number],
|
|
11
|
+
default: uni.$u.props.gap.height
|
|
12
|
+
},
|
|
13
|
+
// 与上一个组件的距离
|
|
14
|
+
marginTop: {
|
|
15
|
+
type: [String, Number],
|
|
16
|
+
default: uni.$u.props.gap.marginTop
|
|
17
|
+
},
|
|
18
|
+
// 与下一个组件的距离
|
|
19
|
+
marginBottom: {
|
|
20
|
+
type: [String, Number],
|
|
21
|
+
default: uni.$u.props.gap.marginBottom
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-gap" :style="[gapStyle]"></view>
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script>
|
|
6
|
+
import props from './props.js';
|
|
7
|
+
/**
|
|
8
|
+
* gap 间隔槽
|
|
9
|
+
* @description 该组件一般用于内容块之间的用一个灰色块隔开的场景,方便用户风格统一,减少工作量
|
|
10
|
+
* @tutorial https://www.uviewui.com/components/gap.html
|
|
11
|
+
* @property {String} bgColor 背景颜色 (默认 'transparent' )
|
|
12
|
+
* @property {String | Number} height 分割槽高度,单位px (默认 20 )
|
|
13
|
+
* @property {String | Number} marginTop 与前一个组件的距离,单位px( 默认 0 )
|
|
14
|
+
* @property {String | Number} marginBottom 与后一个组件的距离,单位px (默认 0 )
|
|
15
|
+
* @property {Object} customStyle 定义需要用到的外部样式
|
|
16
|
+
*
|
|
17
|
+
* @example <u-gap height="80" bg-color="#bbb"></u-gap>
|
|
18
|
+
*/
|
|
19
|
+
export default {
|
|
20
|
+
name: "u-gap",
|
|
21
|
+
mixins: [uni.$u.mpMixin, uni.$u.mixin,props],
|
|
22
|
+
computed: {
|
|
23
|
+
gapStyle() {
|
|
24
|
+
const style = {
|
|
25
|
+
backgroundColor: this.bgColor,
|
|
26
|
+
height: uni.$u.addUnit(this.height),
|
|
27
|
+
marginTop: uni.$u.addUnit(this.marginTop),
|
|
28
|
+
marginBottom: uni.$u.addUnit(this.marginBottom),
|
|
29
|
+
}
|
|
30
|
+
return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle))
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<style lang="scss" scoped>
|
|
37
|
+
@import "../../libs/css/components.scss";
|
|
38
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
props: {
|
|
3
|
+
// 分成几列
|
|
4
|
+
col: {
|
|
5
|
+
type: [String, Number],
|
|
6
|
+
default: uni.$u.props.grid.col
|
|
7
|
+
},
|
|
8
|
+
// 是否显示边框
|
|
9
|
+
border: {
|
|
10
|
+
type: Boolean,
|
|
11
|
+
default: uni.$u.props.grid.border
|
|
12
|
+
},
|
|
13
|
+
// 宫格对齐方式,表现为数量少的时候,靠左,居中,还是靠右
|
|
14
|
+
align: {
|
|
15
|
+
type: String,
|
|
16
|
+
default: uni.$u.props.grid.align
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
class="u-grid"
|
|
4
|
+
ref='u-grid'
|
|
5
|
+
:style="[gridStyle]"
|
|
6
|
+
>
|
|
7
|
+
<slot />
|
|
8
|
+
</view>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script>
|
|
12
|
+
import props from './props.js';
|
|
13
|
+
/**
|
|
14
|
+
* grid 宫格布局
|
|
15
|
+
* @description 宫格组件一般用于同时展示多个同类项目的场景,可以给宫格的项目设置徽标组件(badge),或者图标等,也可以扩展为左右滑动的轮播形式。
|
|
16
|
+
* @tutorial https://www.uviewui.com/components/grid.html
|
|
17
|
+
* @property {String | Number} col 宫格的列数(默认 3 )
|
|
18
|
+
* @property {Boolean} border 是否显示宫格的边框(默认 false )
|
|
19
|
+
* @property {String} align 宫格对齐方式,表现为数量少的时候,靠左,居中,还是靠右 (默认 'left' )
|
|
20
|
+
* @property {Object} customStyle 定义需要用到的外部样式
|
|
21
|
+
* @event {Function} click 点击宫格触发
|
|
22
|
+
* @example <u-grid :col="3" @click="click"></u-grid>
|
|
23
|
+
*/
|
|
24
|
+
export default {
|
|
25
|
+
name: 'u-grid',
|
|
26
|
+
mixins: [uni.$u.mpMixin, uni.$u.mixin,props],
|
|
27
|
+
data() {
|
|
28
|
+
return {
|
|
29
|
+
index: 0,
|
|
30
|
+
width: 0
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
watch: {
|
|
34
|
+
// 当父组件需要子组件需要共享的参数发生了变化,手动通知子组件
|
|
35
|
+
parentData() {
|
|
36
|
+
if (this.children.length) {
|
|
37
|
+
this.children.map(child => {
|
|
38
|
+
// 判断子组件(u-radio)如果有updateParentData方法的话,就就执行(执行的结果是子组件重新从父组件拉取了最新的值)
|
|
39
|
+
typeof(child.updateParentData) == 'function' && child.updateParentData();
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
created() {
|
|
45
|
+
// 如果将children定义在data中,在微信小程序会造成循环引用而报错
|
|
46
|
+
this.children = []
|
|
47
|
+
},
|
|
48
|
+
computed: {
|
|
49
|
+
// 计算父组件的值是否发生变化
|
|
50
|
+
parentData() {
|
|
51
|
+
return [this.hoverClass, this.col, this.size, this.border];
|
|
52
|
+
},
|
|
53
|
+
// 宫格对齐方式
|
|
54
|
+
gridStyle() {
|
|
55
|
+
let style = {};
|
|
56
|
+
switch (this.align) {
|
|
57
|
+
case 'left':
|
|
58
|
+
style.justifyContent = 'flex-start';
|
|
59
|
+
break;
|
|
60
|
+
case 'center':
|
|
61
|
+
style.justifyContent = 'center';
|
|
62
|
+
break;
|
|
63
|
+
case 'right':
|
|
64
|
+
style.justifyContent = 'flex-end';
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
style.justifyContent = 'flex-start';
|
|
68
|
+
};
|
|
69
|
+
return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle));
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
methods: {
|
|
73
|
+
// 此方法由u-grid-item触发,用于在u-grid发出事件
|
|
74
|
+
childClick(name) {
|
|
75
|
+
this.$emit('click', name)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<style lang="scss" scoped>
|
|
82
|
+
@import "../../libs/css/components.scss";
|
|
83
|
+
$u-grid-width:100% !default;
|
|
84
|
+
.u-grid {
|
|
85
|
+
/* #ifdef MP */
|
|
86
|
+
width: $u-grid-width;
|
|
87
|
+
position: relative;
|
|
88
|
+
box-sizing: border-box;
|
|
89
|
+
overflow: hidden;
|
|
90
|
+
display: block;
|
|
91
|
+
/* #endif */
|
|
92
|
+
justify-content: center;
|
|
93
|
+
@include flex;
|
|
94
|
+
flex-wrap: wrap;
|
|
95
|
+
align-items: center;
|
|
96
|
+
}
|
|
97
|
+
</style>
|