123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- "use strict";
- const common_vendor = require("../../../../common/vendor.js");
- const _sfc_main = {
- name: "UniBadge",
- emits: ["click"],
- props: {
- type: {
- type: String,
- default: "error"
- },
- inverted: {
- type: Boolean,
- default: false
- },
- isDot: {
- type: Boolean,
- default: false
- },
- maxNum: {
- type: Number,
- default: 99
- },
- absolute: {
- type: String,
- default: ""
- },
- offset: {
- type: Array,
- default() {
- return [0, 0];
- }
- },
- text: {
- type: [String, Number],
- default: ""
- },
- size: {
- type: String,
- default: "small"
- },
- customStyle: {
- type: Object,
- default() {
- return {};
- }
- }
- },
- data() {
- return {};
- },
- computed: {
- width() {
- return String(this.text).length * 8 + 12;
- },
- classNames() {
- const {
- inverted,
- type,
- size,
- absolute
- } = this;
- return [
- inverted ? "uni-badge--" + type + "-inverted" : "",
- "uni-badge--" + type,
- "uni-badge--" + size,
- absolute ? "uni-badge--absolute" : ""
- ].join(" ");
- },
- positionStyle() {
- if (!this.absolute)
- return {};
- let w = this.width / 2, h = 10;
- if (this.isDot) {
- w = 5;
- h = 5;
- }
- const x = `${-w + this.offset[0]}px`;
- const y = `${-h + this.offset[1]}px`;
- const whiteList = {
- rightTop: {
- right: x,
- top: y
- },
- rightBottom: {
- right: x,
- bottom: y
- },
- leftBottom: {
- left: x,
- bottom: y
- },
- leftTop: {
- left: x,
- top: y
- }
- };
- const match = whiteList[this.absolute];
- return match ? match : whiteList["rightTop"];
- },
- badgeWidth() {
- return {
- width: `${this.width}px`
- };
- },
- dotStyle() {
- if (!this.isDot)
- return {};
- return {
- width: "10px",
- height: "10px",
- borderRadius: "10px"
- };
- },
- displayValue() {
- const {
- isDot,
- text,
- maxNum
- } = this;
- return isDot ? "" : Number(text) > maxNum ? `${maxNum}+` : text;
- }
- },
- methods: {
- onClick() {
- this.$emit("click");
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: $props.text
- }, $props.text ? {
- b: common_vendor.t($options.displayValue),
- c: common_vendor.n($options.classNames),
- d: common_vendor.s($options.badgeWidth),
- e: common_vendor.s($options.positionStyle),
- f: common_vendor.s($props.customStyle),
- g: common_vendor.s($options.dotStyle),
- h: common_vendor.o(($event) => $options.onClick())
- } : {});
- }
- const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-c97cb896"], ["__file", "D:/zx/mall-front-app/uni_modules/uni-badge/components/uni-badge/uni-badge.vue"]]);
- wx.createComponent(Component);
|