Browse Source

配置文件更改

bding 1 year ago
parent
commit
f68c2f3e7c

+ 0 - 1
.gitignore

@@ -1,5 +1,4 @@
 unpackage/
 node_modules/
-wxcomponents/
 .Ds_Store
 .hbuilderx

+ 1 - 0
wxcomponents/vant/dist/cascader/index.d.ts

@@ -0,0 +1 @@
+export {};

+ 208 - 0
wxcomponents/vant/dist/cascader/index.js

@@ -0,0 +1,208 @@
+import { VantComponent } from '../common/component';
+var FieldName;
+(function (FieldName) {
+    FieldName["TEXT"] = "text";
+    FieldName["VALUE"] = "value";
+    FieldName["CHILDREN"] = "children";
+})(FieldName || (FieldName = {}));
+const defaultFieldNames = {
+    text: FieldName.TEXT,
+    value: FieldName.VALUE,
+    children: FieldName.CHILDREN,
+};
+VantComponent({
+    props: {
+        title: String,
+        value: {
+            type: String,
+            observer: 'updateValue',
+        },
+        placeholder: {
+            type: String,
+            value: '请选择',
+        },
+        activeColor: {
+            type: String,
+            value: '#1989fa',
+        },
+        options: {
+            type: Array,
+            value: [],
+            observer: 'updateOptions',
+        },
+        swipeable: {
+            type: Boolean,
+            value: false,
+        },
+        closeable: {
+            type: Boolean,
+            value: true,
+        },
+        showHeader: {
+            type: Boolean,
+            value: true,
+        },
+        closeIcon: {
+            type: String,
+            value: 'cross',
+        },
+        fieldNames: {
+            type: Object,
+            value: defaultFieldNames,
+            observer: 'updateFieldNames',
+        },
+    },
+    data: {
+        tabs: [],
+        activeTab: 0,
+        textKey: FieldName.TEXT,
+        valueKey: FieldName.VALUE,
+        childrenKey: FieldName.CHILDREN,
+    },
+    created() {
+        this.updateTabs();
+    },
+    methods: {
+        updateOptions(val, oldVal) {
+            const isAsync = !!(val.length && oldVal.length);
+            this.updateTabs(isAsync);
+        },
+        updateValue(val) {
+            if (val !== undefined) {
+                const values = this.data.tabs.map((tab) => tab.selected && tab.selected[this.data.valueKey]);
+                if (values.indexOf(val) > -1) {
+                    return;
+                }
+            }
+            this.updateTabs();
+        },
+        updateFieldNames() {
+            const { text = 'text', value = 'value', children = 'children', } = this.data.fieldNames || defaultFieldNames;
+            this.setData({
+                textKey: text,
+                valueKey: value,
+                childrenKey: children,
+            });
+        },
+        getSelectedOptionsByValue(options, value) {
+            for (let i = 0; i < options.length; i++) {
+                const option = options[i];
+                if (option[this.data.valueKey] === value) {
+                    return [option];
+                }
+                if (option[this.data.childrenKey]) {
+                    const selectedOptions = this.getSelectedOptionsByValue(option[this.data.childrenKey], value);
+                    if (selectedOptions) {
+                        return [option, ...selectedOptions];
+                    }
+                }
+            }
+        },
+        updateTabs(isAsync = false) {
+            const { options, value } = this.data;
+            if (value !== undefined) {
+                const selectedOptions = this.getSelectedOptionsByValue(options, value);
+                if (selectedOptions) {
+                    let optionsCursor = options;
+                    const tabs = selectedOptions.map((option) => {
+                        const tab = {
+                            options: optionsCursor,
+                            selected: option,
+                        };
+                        const next = optionsCursor.find((item) => item[this.data.valueKey] === option[this.data.valueKey]);
+                        if (next) {
+                            optionsCursor = next[this.data.childrenKey];
+                        }
+                        return tab;
+                    });
+                    if (optionsCursor) {
+                        tabs.push({
+                            options: optionsCursor,
+                            selected: null,
+                        });
+                    }
+                    this.setData({
+                        tabs,
+                    });
+                    wx.nextTick(() => {
+                        this.setData({
+                            activeTab: tabs.length - 1,
+                        });
+                    });
+                    return;
+                }
+            }
+            // 异步更新
+            if (isAsync) {
+                const { tabs } = this.data;
+                tabs[tabs.length - 1].options =
+                    options[options.length - 1][this.data.childrenKey];
+                this.setData({
+                    tabs,
+                });
+                return;
+            }
+            this.setData({
+                tabs: [
+                    {
+                        options,
+                        selected: null,
+                    },
+                ],
+            });
+        },
+        onClose() {
+            this.$emit('close');
+        },
+        onClickTab(e) {
+            const { index: tabIndex, title } = e.detail;
+            this.$emit('click-tab', { title, tabIndex });
+            this.setData({
+                activeTab: tabIndex,
+            });
+        },
+        // 选中
+        onSelect(e) {
+            const { option, tabIndex } = e.currentTarget.dataset;
+            if (option && option.disabled) {
+                return;
+            }
+            const { valueKey, childrenKey } = this.data;
+            let { tabs } = this.data;
+            tabs[tabIndex].selected = option;
+            if (tabs.length > tabIndex + 1) {
+                tabs = tabs.slice(0, tabIndex + 1);
+            }
+            if (option[childrenKey]) {
+                const nextTab = {
+                    options: option[childrenKey],
+                    selected: null,
+                };
+                if (tabs[tabIndex + 1]) {
+                    tabs[tabIndex + 1] = nextTab;
+                }
+                else {
+                    tabs.push(nextTab);
+                }
+                wx.nextTick(() => {
+                    this.setData({
+                        activeTab: tabIndex + 1,
+                    });
+                });
+            }
+            this.setData({
+                tabs,
+            });
+            const selectedOptions = tabs.map((tab) => tab.selected).filter(Boolean);
+            const params = {
+                value: option[valueKey],
+                tabIndex,
+                selectedOptions,
+            };
+            this.$emit('change', params);
+            if (!option[childrenKey]) {
+                this.$emit('finish', params);
+            }
+        },
+    },
+});

+ 8 - 0
wxcomponents/vant/dist/cascader/index.json

@@ -0,0 +1,8 @@
+{
+  "component": true,
+  "usingComponents": {
+    "van-icon": "../icon/index",
+    "van-tab":  "../tab/index",
+    "van-tabs": "../tabs/index"
+  }
+}

+ 53 - 0
wxcomponents/vant/dist/cascader/index.wxml

@@ -0,0 +1,53 @@
+<wxs src="./index.wxs" module="utils" />
+
+<view wx:if="{{ showHeader }}" class="van-cascader__header">
+  <text class="van-cascader__title"><slot name="title"></slot>{{ title }}</text>
+  <van-icon
+    wx:if="{{ closeable }}"
+    name="{{ closeIcon }}"
+    class="van-cascader__close-icon"
+    bind:tap="onClose"
+  />
+</view>
+
+<van-tabs
+  active="{{ activeTab }}"
+  custom-class="van-cascader__tabs"
+  wrap-class="van-cascader__tabs-wrap"
+  tab-class="van-cascader__tab"
+  color="{{ activeColor }}"
+  border="{{ false }}"
+  swipeable="{{ swipeable }}"
+  bind:click="onClickTab"
+>
+  <van-tab
+    wx:for="{{ tabs }}"
+    wx:for-item="tab"
+    wx:for-index="tabIndex"
+    wx:key="tabIndex"
+    title="{{ tab.selected ? tab.selected[textKey] : placeholder }}"
+    style="width: 100%;"
+    title-style="{{ !tab.selected ? 'color: #969799;font-weight:normal;' : '' }}"
+  >
+    <!-- 暂不支持 -->
+    <!-- <slot name="options-top"></slot> -->
+
+    <view class="van-cascader__options">
+      <view
+        wx:for="{{ tab.options }}"
+        wx:for-item="option"
+        wx:key="index"
+        class="{{ option.className }} {{ utils.optionClass(tab, textKey, option) }}"
+        style="{{ utils.optionStyle({ tab, textKey, option, activeColor }) }}"
+        data-option="{{ option }}"
+        data-tab-index="{{ tabIndex }}"
+        bind:tap="onSelect"
+      >
+        <text>{{ option[textKey] }}</text>
+        <van-icon wx:if="{{ utils.isSelected(tab, textKey, option) }}" name="success" size="18" />
+      </view>
+    </view>
+    <!-- 暂不支持 -->
+    <!-- <slot name="options-bottom"></slot> -->
+  </van-tab>
+</van-tabs>

+ 24 - 0
wxcomponents/vant/dist/cascader/index.wxs

@@ -0,0 +1,24 @@
+var utils = require('../wxs/utils.wxs');
+var style = require('../wxs/style.wxs');
+
+function isSelected(tab, textKey, option) {
+  return tab.selected && tab.selected[textKey] === option[textKey]
+}
+
+function optionClass(tab, textKey, option) {
+  return utils.bem('cascader__option', { selected: isSelected({ tab, textKey, option }), disabled: option.disabled })
+}
+
+function optionStyle(data) {
+  var color = data.option.color || (isSelected(data.tab, data.textKey, data.option) ? data.activeColor : undefined);
+  return style({
+    color
+  });
+}
+
+
+module.exports = {
+  isSelected: isSelected,
+  optionClass: optionClass,
+  optionStyle: optionStyle,
+};

+ 1 - 0
wxcomponents/vant/dist/cascader/index.wxss

@@ -0,0 +1 @@
+@import '../common/index.wxss';.van-cascader__header{align-items:center;display:flex;height:48px;justify-content:space-between;padding:0 16px}.van-cascader__title{font-size:16px;font-weight:600;line-height:20px}.van-cascader__close-icon{color:#c8c9cc;font-size:22px;height:22px}.van-cascader__tabs-wrap{height:48px!important;padding:0 8px}.van-cascader__tab{color:#323233!important;flex:none!important;font-weight:600!important;padding:0 8px!important}.van-cascader__tab--unselected{color:#969799!important;font-weight:400!important}.van-cascader__option{align-items:center;cursor:pointer;display:flex;font-size:14px;justify-content:space-between;line-height:20px;padding:10px 16px}.van-cascader__option:active{background-color:#f2f3f5}.van-cascader__option--selected{color:#1989fa;font-weight:600}.van-cascader__option--disabled{color:#c8c9cc;cursor:not-allowed}.van-cascader__option--disabled:active{background-color:initial}.van-cascader__options{-webkit-overflow-scrolling:touch;box-sizing:border-box;height:384px;overflow-y:auto;padding-top:6px}

+ 1 - 0
wxcomponents/vant/dist/config-provider/index.d.ts

@@ -0,0 +1 @@
+export {};

+ 9 - 0
wxcomponents/vant/dist/config-provider/index.js

@@ -0,0 +1,9 @@
+import { VantComponent } from '../common/component';
+VantComponent({
+    props: {
+        themeVars: {
+            type: Object,
+            value: {},
+        },
+    },
+});

+ 3 - 0
wxcomponents/vant/dist/config-provider/index.json

@@ -0,0 +1,3 @@
+{
+  "component": true
+}

+ 5 - 0
wxcomponents/vant/dist/config-provider/index.wxml

@@ -0,0 +1,5 @@
+<wxs src="./index.wxs" module="computed" />
+
+<view class="van-config-provider" style="{{ computed.mapThemeVarsToCSSVars(themeVars) }}">
+  <slot />
+</view>

+ 29 - 0
wxcomponents/vant/dist/config-provider/index.wxs

@@ -0,0 +1,29 @@
+/* eslint-disable */
+var object = require('../wxs/object.wxs');
+var style = require('../wxs/style.wxs');
+
+function kebabCase(word) {
+  var newWord = word
+    .replace(getRegExp("[A-Z]", 'g'), function (i) {
+      return '-' + i;
+    })
+    .toLowerCase()
+    .replace(getRegExp("^-"), '');
+
+  return newWord;
+}
+
+function mapThemeVarsToCSSVars(themeVars) {
+  var cssVars = {};
+  object.keys(themeVars).forEach(function (key) {
+    var cssVarsKey = '--' + kebabCase(key);
+    cssVars[cssVarsKey] = themeVars[key];
+  });
+
+  return style(cssVars);
+}
+
+module.exports = {
+  kebabCase: kebabCase,
+  mapThemeVarsToCSSVars: mapThemeVarsToCSSVars,
+};

+ 8 - 0
wxcomponents/vant/dist/field/types.d.ts

@@ -0,0 +1,8 @@
+export interface InputDetails {
+    /** 输入框内容 */
+    value: string;
+    /** 光标位置 */
+    cursor?: number;
+    /** keyCode 为键值 (目前工具还不支持返回keyCode参数) `2.1.0` 起支持 */
+    keyCode?: number;
+}

+ 1 - 0
wxcomponents/vant/dist/field/types.js

@@ -0,0 +1 @@
+export {};

+ 10 - 0
wxcomponents/vant/dist/overlay/overlay.wxml

@@ -0,0 +1,10 @@
+<van-transition
+  show="{{ show }}"
+  custom-class="van-overlay custom-class"
+  custom-style="z-index: {{ zIndex }}; {{ customStyle }}"
+  duration="{{ duration }}"
+  bind:tap="onClick"
+  catch:touchmove="{{ lockScroll ? 'noop' : ''}}"
+>
+  <slot></slot>
+</van-transition>

+ 14 - 0
wxcomponents/vant/dist/popup/popup.wxml

@@ -0,0 +1,14 @@
+<view
+  wx:if="{{ inited }}"
+  class="custom-class {{ classes }} {{ utils.bem('popup', [position, { round, safe: safeAreaInsetBottom, safeTop: safeAreaInsetTop, safeTabBar: safeAreaTabBar }]) }}"
+  style="{{ computed.popupStyle({ zIndex, currentDuration, display, customStyle }) }}"
+  bind:transitionend="onTransitionEnd"
+>
+  <slot />
+  <van-icon
+    wx:if="{{ closeable }}"
+    name="{{ closeIcon }}"
+    class="close-icon-class van-popup__close-icon van-popup__close-icon--{{ closeIconPosition }}"
+    bind:tap="onClickCloseIcon"
+  />
+</view>