This commit is contained in:
zyronon 2022-03-24 17:48:23 +08:00
parent cd4306bf68
commit 5e5f42085e
6 changed files with 4341 additions and 28 deletions

4269
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,6 @@
"serve": "vite preview" "serve": "vite preview"
}, },
"dependencies": { "dependencies": {
"vue": "3.2.16",
"@jambonn/vue-lazyload": "1.0.8", "@jambonn/vue-lazyload": "1.0.8",
"axios": "0.21.1", "axios": "0.21.1",
"core-js": "3.6.5", "core-js": "3.6.5",
@ -16,6 +15,7 @@
"mitt": "2.1.0", "mitt": "2.1.0",
"mockjs": "1.1.0", "mockjs": "1.1.0",
"pinyin": "2.9.0", "pinyin": "2.9.0",
"vue": "3.2.16",
"vue-router": "4.0.8", "vue-router": "4.0.8",
"vue-switches": "2.0.1", "vue-switches": "2.0.1",
"vuex": "4.0.1" "vuex": "4.0.1"
@ -23,9 +23,8 @@
"devDependencies": { "devDependencies": {
"@vitejs/plugin-vue": "1.9.3", "@vitejs/plugin-vue": "1.9.3",
"@vitejs/plugin-vue-jsx": "1.2.0", "@vitejs/plugin-vue-jsx": "1.2.0",
"vite": "2.6.4", "less": "^4.1.2",
"less": "4.1.1", "mobile-select": "1.1.2",
"less-loader": "7.0.0", "vite": "2.8.5"
"mobile-select": "1.1.2"
} }
} }

View File

@ -189,7 +189,7 @@ export default {
this.tabIndicatorRelationActiveIndexLefts.push( this.tabIndicatorRelationActiveIndexLefts.push(
item.getBoundingClientRect().x - tabs.children[0].getBoundingClientRect().x + (this.isHome ? this.tabWidth * 0.15 : 0)) item.getBoundingClientRect().x - tabs.children[0].getBoundingClientRect().x + (this.isHome ? this.tabWidth * 0.15 : 0))
} }
// console.log(this.indicatorRelateIndexLefts) // console.log(this.lefts)
this.indicatorSpace = this.tabIndicatorRelationActiveIndexLefts[1] - this.tabIndicatorRelationActiveIndexLefts[0] this.indicatorSpace = this.tabIndicatorRelationActiveIndexLefts[1] - this.tabIndicatorRelationActiveIndexLefts[0]
if (this.isHome) { if (this.isHome) {
this.$setCss(this.indicatorRef, 'transition-duration', `300ms`) this.$setCss(this.indicatorRef, 'transition-duration', `300ms`)

View File

@ -6,16 +6,15 @@
<div class="tab-ctn"> <div class="tab-ctn">
<div class="tabs" ref="tabs"> <div class="tabs" ref="tabs">
<div class="tab" <div class="tab"
@click="changeIndex(false,0)"> @click.stop="changeIndex(0)">
<span>同城</span> <span>同城</span>
</div> </div>
<div class="tab" <div class="tab"
@click.stop="changeIndex(1)">
@click="changeIndex(false,0)">
<span>关注</span> <span>关注</span>
</div> </div>
<div class="tab" <div class="tab"
@click="changeIndex(false,1)"><span>推荐</span> @click.stop="changeIndex(2)"><span>推荐</span>
</div> </div>
</div> </div>
<div class="indicator" ref="indicator"></div> <div class="indicator" ref="indicator"></div>
@ -29,6 +28,7 @@
</template> </template>
<script> <script>
import Loading from "../../components/Loading"; import Loading from "../../components/Loading";
import bus from "../../utils/bus";
export default { export default {
name: "IndicatorHome", name: "IndicatorHome",
@ -36,13 +36,21 @@ export default {
Loading, Loading,
}, },
props: { props: {
modelValue: false modelValue: false,
//slidListslidListindicator
name: {
type: String,
default: () => ''
},
index: {
type: Number,
default: () => 0
},
}, },
data() { data() {
return { return {
tabWidth: 0,
indicatorRef: null, indicatorRef: null,
indicatorRelateIndexLefts: [], lefts: [],
indicatorSpace: 0 indicatorSpace: 0
} }
}, },
@ -51,23 +59,44 @@ export default {
created() { created() {
}, },
mounted() { mounted() {
let tabs = this.$refs.tabs this.initTabs()
this.indicatorRef = this.$refs.indicator bus.on(this.name + '-moved', this.move)
for (let i = 0; i < tabs.children.length; i++) { bus.on(this.name + '-end', this.end)
let item = tabs.children[i]
this.tabWidth = this.$getCss(item, 'width')
//TODO IndicatorLight.vue
this.indicatorRelateIndexLefts.push(
item.getBoundingClientRect().x - tabs.children[0].getBoundingClientRect().x + this.tabWidth * 0.15)
}
this.indicatorSpace = this.indicatorRelateIndexLefts[1] - this.indicatorRelateIndexLefts[0]
this.$setCss(this.indicatorRef, 'transition-duration', `300ms`)
this.$setCss(this.indicatorRef, 'left', this.indicatorRelateIndexLefts[0] + 'px')
}, },
methods: { methods: {
changeIndex() { changeIndex(index) {
this.$emit('update:index', index)
this.$setCss(this.indicatorRef, 'transition-duration', `300ms`)
this.$setCss(this.indicatorRef, 'left', this.lefts[index] + 'px')
},
initTabs() {
let tabs = this.$refs.tabs
this.indicatorRef = this.$refs.indicator
let indicatorWidth = this.$getCss(this.indicatorRef, 'width')
for (let i = 0; i < tabs.children.length; i++) {
let item = tabs.children[i]
let tabWidth = this.$getCss(item, 'width')
this.lefts.push(
item.getBoundingClientRect().x - tabs.children[0].getBoundingClientRect().x + (tabWidth * 0.5 - indicatorWidth / 2))
}
this.indicatorSpace = this.lefts[1] - this.lefts[this.index]
this.$setCss(this.indicatorRef, 'transition-duration', `300ms`)
this.$setCss(this.indicatorRef, 'left', this.lefts[this.index] + 'px')
},
move(e) {
console.log('move', e)
this.$setCss(this.indicatorRef, 'left',
this.lefts[this.index] -
e.x.distance / (this.$store.state.bodyWidth / this.indicatorSpace) + 'px')
},
end(index) {
console.log(index)
this.$setCss(this.indicatorRef, 'transition-duration', `300ms`)
this.$setCss(this.indicatorRef, 'left', this.lefts[this.index] + 'px')
setTimeout(() => {
this.$setCss(this.indicatorRef, 'transition-duration', `0ms`)
}, 300)
} }
} }
} }

View File

@ -1,5 +1,13 @@
<script lang="jsx"> <script lang="jsx">
import bus from "../../utils/bus";
export default { export default {
props:{
name: {
type: String,
default: () => ''
},
},
data() { data() {
return { return {
wrapper: null, wrapper: null,
@ -35,9 +43,13 @@ export default {
let isRight = this.moveX < 0 let isRight = this.moveX < 0
if ((this.index === 0 && !isRight) || (this.index === this.total - 1 && isRight)) return if ((this.index === 0 && !isRight) || (this.index === this.total - 1 && isRight)) return
this.checkDirection(e) this.checkDirection(e)
if (this.next) { if (this.next) {
bus.emit(this.name + '-moved', {
x: {distance: this.moveX, isRight},
})
this.$stopPropagation(e) this.$stopPropagation(e)
this.$setCss(this.wrapper, 'transform', this.$setCss(this.wrapper, 'transform',
`translate3d(${this.getDistance() `translate3d(${this.getDistance()

View File

@ -2,8 +2,12 @@
<div id="Slide" @click="checkDbClick"> <div id="Slide" @click="checkDbClick">
<slide-horizontal> <slide-horizontal>
<div class="item"> <div class="item">
<IndicatorHome/> <IndicatorHome
name="main"
v-model:index="index"
/>
<slide-horizontal <slide-horizontal
name="main"
v-model:index="index" v-model:index="index"
style="height: calc(100% - 5rem);" style="height: calc(100% - 5rem);"
> >