From 290bf03803f24befe259ae201e04e4b73751c5a3 Mon Sep 17 00:00:00 2001
From: whycq <913841844@qq.com>
Date: 星期四, 17 八月 2023 23:05:48 +0800
Subject: [PATCH] #
---
uni_modules/uni-segmented-control/components/uni-segmented-control/uni-segmented-control.vue | 145 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 145 insertions(+), 0 deletions(-)
diff --git a/uni_modules/uni-segmented-control/components/uni-segmented-control/uni-segmented-control.vue b/uni_modules/uni-segmented-control/components/uni-segmented-control/uni-segmented-control.vue
new file mode 100644
index 0000000..044a495
--- /dev/null
+++ b/uni_modules/uni-segmented-control/components/uni-segmented-control/uni-segmented-control.vue
@@ -0,0 +1,145 @@
+<template>
+ <view :class="[styleType === 'text'?'segmented-control--text' : 'segmented-control--button' ]"
+ :style="{ borderColor: styleType === 'text' ? '' : activeColor }" class="segmented-control">
+ <view v-for="(item, index) in values" :class="[ styleType === 'text' ? '': 'segmented-control__item--button',
+ index === currentIndex&&styleType === 'button' ? 'segmented-control__item--button--active': '',
+ index === 0&&styleType === 'button' ? 'segmented-control__item--button--first': '',
+ index === values.length - 1&&styleType === 'button' ? 'segmented-control__item--button--last': '' ]" :key="index"
+ :style="{ backgroundColor: index === currentIndex && styleType === 'button' ? activeColor : '',borderColor: index === currentIndex&&styleType === 'text'||styleType === 'button'?activeColor:'transparent' }"
+ class="segmented-control__item" @click="_onClick(index)">
+ <view>
+ <text :style="{color:
+ index === currentIndex
+ ? styleType === 'text'
+ ? activeColor
+ : '#fff'
+ : styleType === 'text'
+ ? '#000'
+ : activeColor}" class="segmented-control__text" :class="styleType === 'text' && index === currentIndex ? 'segmented-control__item--text': ''">{{ item }}</text>
+ </view>
+
+ </view>
+ </view>
+</template>
+
+<script>
+ /**
+ * SegmentedControl 鍒嗘鍣�
+ * @description 鐢ㄤ綔涓嶅悓瑙嗗浘鐨勬樉绀�
+ * @tutorial https://ext.dcloud.net.cn/plugin?id=54
+ * @property {Number} current 褰撳墠閫変腑鐨則ab绱㈠紩鍊硷紝浠�0璁℃暟
+ * @property {String} styleType = [button|text] 鍒嗘鍣ㄦ牱寮忕被鍨�
+ * @value button 鎸夐挳绫诲瀷
+ * @value text 鏂囧瓧绫诲瀷
+ * @property {String} activeColor 閫変腑鐨勬爣绛捐儗鏅壊涓庤竟妗嗛鑹�
+ * @property {Array} values 閫夐」鏁扮粍
+ * @event {Function} clickItem 缁勪欢瑙﹀彂鐐瑰嚮浜嬩欢鏃惰Е鍙戯紝e={currentIndex}
+ */
+
+ export default {
+ name: 'UniSegmentedControl',
+ emits: ['clickItem'],
+ props: {
+ current: {
+ type: Number,
+ default: 0
+ },
+ values: {
+ type: Array,
+ default () {
+ return []
+ }
+ },
+ activeColor: {
+ type: String,
+ default: '#2979FF'
+ },
+ styleType: {
+ type: String,
+ default: 'button'
+ }
+ },
+ data() {
+ return {
+ currentIndex: 0
+ }
+ },
+ watch: {
+ current(val) {
+ if (val !== this.currentIndex) {
+ this.currentIndex = val
+ }
+ }
+ },
+ created() {
+ this.currentIndex = this.current
+ },
+ methods: {
+ _onClick(index) {
+ if (this.currentIndex !== index) {
+ this.currentIndex = index
+ this.$emit('clickItem', {
+ currentIndex: index
+ })
+ }
+ }
+ }
+ }
+</script>
+
+<style lang="scss" scoped>
+ .segmented-control {
+ /* #ifndef APP-NVUE */
+ display: flex;
+ box-sizing: border-box;
+ /* #endif */
+ flex-direction: row;
+ height: 36px;
+ overflow: hidden;
+ /* #ifdef H5 */
+ cursor: pointer;
+ /* #endif */
+ }
+
+ .segmented-control__item {
+ /* #ifndef APP-NVUE */
+ display: inline-flex;
+ box-sizing: border-box;
+ /* #endif */
+ position: relative;
+ flex: 1;
+ justify-content: center;
+ align-items: center;
+ }
+
+ .segmented-control__item--button {
+ border-style: solid;
+ border-top-width: 1px;
+ border-bottom-width: 1px;
+ border-right-width: 1px;
+ border-left-width: 0;
+ }
+
+ .segmented-control__item--button--first {
+ border-left-width: 1px;
+ border-top-left-radius: 5px;
+ border-bottom-left-radius: 5px;
+ }
+
+ .segmented-control__item--button--last {
+ border-top-right-radius: 5px;
+ border-bottom-right-radius: 5px;
+ }
+
+ .segmented-control__item--text {
+ border-bottom-style: solid;
+ border-bottom-width: 2px;
+ padding: 6px 0;
+ }
+
+ .segmented-control__text {
+ font-size: 14px;
+ line-height: 20px;
+ text-align: center;
+ }
+</style>
--
Gitblit v1.9.1