1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <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,
- }
- },
- emits: ["select-item"],
- created() {
- this.currentItemIndex = this.defaultIndex;
- },
- 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">
- <div class="button-block_item" v-for="(item,index) in items" :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')}`
- }" @click="onClickBlockItemHandler(index)" />
- </div>
- </div>
- </template>
- <style scoped lang='less'>
- .button-block {
- display: flex;
- border-radius: 5px;
- box-sizing: border-box;
- background: linear-gradient(
- 0deg,
- #0094FF90 0%,
- #0094FF10 100%
- );
- .button-block_item {
- padding: 0px 8.5px 0px 8.5px;
- cursor: pointer;
- }
- }
- </style>
|