123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <script>
- import LinearText from "../LinearText";
- export default {
- name: "ButtonBlock",
- components: {
- LinearText,
- },
- props: {
- items: {
- type: Array,
- default: () => ["本日", "本周", "本月"],
- },
- valueField: {
- type: String,
- default: "",
- },
- defaultIndex: {
- type: Number,
- default: 0,
- },
- },
- data() {
- return {
- currentItemIndex: 0,
- height: 0,
- width: 0,
- };
- },
- emits: ["select-item"],
- created() {
- this.currentItemIndex = this.defaultIndex;
- },
- computed: {
- buttonBlockStyle() {
- return {
- "--height": `${this.height}px`,
- "--width": `${this.width}px`,
- };
- },
- },
- mounted() {
- const dom = this.$refs.buttonBlock;
- this.height = dom.clientHeight;
- this.width = dom.clientWidth;
- },
- methods: {
-
- renderCurrentItemColor(index, color) {
- return this.currentItemIndex === index ? color : `${color}88`;
- },
-
- renderText(item) {
- if (this.valueField === "") {
- return item;
- } else {
- return item[this.valueField];
- }
- },
-
- onClickBlockItemHandler(index) {
- this.currentItemIndex = index;
- this.$emit("select-item", index);
- },
- },
- };
- </script>
- <template>
- <div class="button-block" ref="buttonBlock" :style="buttonBlockStyle">
- <div class="button-block_item" v-for="(item, index) in items"
- @click="onClickBlockItemHandler(index)" :key="index">
- <linear-text
- :text="renderText(item)"
- :startColor="renderCurrentItemColor(index, '#95CCFF')"
- :endColor="renderCurrentItemColor(index, '#FFFFFF')"
- fontSize="16px"
- :ext-class="{
- textShadow: `0 1px 1px ${renderCurrentItemColor(index, '#0057FF')}`,
- }"
- />
- </div>
- </div>
- </template>
- <style scoped lang="less">
- .button-block {
- display: flex;
- position: relative;
- border-radius: 5px;
- box-sizing: border-box;
- background: linear-gradient(360deg, #0094ff90 0%, #0094ff10 100%);
- .button-block_item {
- padding: 0px 8.5px 0px 8.5px;
- cursor: pointer;
- }
- &::after {
- content: "";
- position: absolute;
- top: 0px;
- left: 0px;
- padding: 1px;
- box-sizing: border-box;
- border-radius: 5px;
- width: var(
- height: var(
- background: linear-gradient(360deg, rgba(0, 163, 255, 0) 0%, #0c5a87 100%);
-
-
-
-
-
- -webkit-mask-image: var(
-
- -webkit-mask-origin: var(
-
- -webkit-mask-clip: var(
-
- mask-composite: exclude;
-
- -webkit-mask-composite: destination-out;
- pointer-events: none;
- }
- }
- </style>
|