123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const _sfc_main = {
- name: "EvanSwitch",
- props: {
- value: {
- type: [String, Number, Boolean],
- default: false
- },
- activeColor: {
- type: String,
- default: "#108ee9"
- },
- inactiveColor: {
- type: String,
- default: "#fff"
- },
- size: {
- type: Number,
- default: 30
- },
- disabled: {
- type: Boolean,
- default: false
- },
- activeValue: {
- type: [String, Number, Boolean],
- default: true
- },
- inactiveValue: {
- type: [String, Number, Boolean],
- default: false
- },
- beforeChange: {
- type: Function,
- default: null
- },
- extraData: null,
- contextLevel: {
- type: Number,
- default: 1
- }
- },
- computed: {
- switchHeight() {
- return this.size + "px";
- }
- },
- watch: {
- value: {
- immediate: true,
- handler(value) {
- this.currentValue = value;
- }
- }
- },
- data() {
- return {
- currentValue: false
- };
- },
- methods: {
- toggle() {
- if (!this.disabled) {
- if (this.beforeChange && typeof this.beforeChange === "function") {
- let context = this;
- for (let i = 0; i < this.contextLevel; i++) {
- context = context.$options.parent;
- }
- const result = this.beforeChange(
- this.currentValue === this.activeValue ? this.inactiveValue : this.activeValue,
- this.extraData,
- context
- );
- if (typeof result === "object") {
- result.then(() => {
- this.toggleValue();
- }).catch(() => {
- });
- } else if (typeof result === "boolean" && result) {
- this.toggleValue();
- }
- } else {
- this.toggleValue();
- }
- }
- },
- toggleValue() {
- this.currentValue = this.currentValue === this.activeValue ? this.inactiveValue : this.activeValue;
- this.$emit("input", this.currentValue);
- this.$emit("change", this.currentValue);
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return {
- a: $data.currentValue === $props.activeValue ? `translateX(${29}px)` : `translateX(0)`,
- b: common_vendor.o((...args) => $options.toggle && $options.toggle(...args)),
- c: $props.disabled ? 1 : "",
- d: $data.currentValue === $props.activeValue ? $props.activeColor : $props.inactiveColor
- };
- }
- const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-687346f1"]]);
- wx.createComponent(Component);
|