代码优化

master
wayn 12 months ago
parent e70807d070
commit 6f0a620af1

@ -4,7 +4,7 @@
<van-tabbar v-model="active" :active-color="variables.theme" :fixed="false" route> <van-tabbar v-model="active" :active-color="variables.theme" :fixed="false" route>
<van-tabbar-item :to="{name: 'Home'}" icon="wap-home">首页</van-tabbar-item> <van-tabbar-item :to="{name: 'Home'}" icon="wap-home">首页</van-tabbar-item>
<van-tabbar-item :to="{name: 'Category'}" icon="bars">分类</van-tabbar-item> <van-tabbar-item :to="{name: 'Category'}" icon="bars">分类</van-tabbar-item>
<van-tabbar-item :to="{name: 'Cart'}" icon="shopping-cart">购物车</van-tabbar-item> <van-tabbar-item :to="{name: 'Cart'}" icon="shopping-cart" :badge="totalCartNum">购物车</van-tabbar-item>
<van-tabbar-item :to="{name: 'User'}" icon="manager">我的</van-tabbar-item> <van-tabbar-item :to="{name: 'User'}" icon="manager">我的</van-tabbar-item>
</van-tabbar> </van-tabbar>
</div> </div>
@ -14,16 +14,36 @@
<script> <script>
import variables from '@/styles/variables.scss' import variables from '@/styles/variables.scss'
import { getCartGoodsCount } from '@/api/cart'
export default { export default {
data() { data() {
return { return {
active: 0 active: 0,
count: 0
} }
}, },
computed: { computed: {
variables() { variables() {
return variables return variables
},
totalCartNum() {
if (this.count === 0) {
return ''
} else {
return this.count <= 99 ? this.count : 99
}
}
},
mounted() {
this.getCartGoodsCount()
},
methods: {
getCartGoodsCount() {
getCartGoodsCount().then(res => {
const { count } = res.map
this.count = count
}).catch(e => {})
} }
} }
} }

@ -50,7 +50,7 @@ service.interceptors.response.use(
return return
} }
// 订单轮询 // 订单轮询
if (res.code === 5002) { if (res.code === 5001) {
return Promise.reject(new Error(res.msg || 'Error')) return Promise.reject(new Error(res.msg || 'Error'))
} }
Toast.fail(res.msg) Toast.fail(res.msg)

@ -6,6 +6,7 @@
:key="idx" :key="idx"
:index="item.id" :index="item.id"
:num="item.number" :num="item.number"
:max-num="item.maxNum"
:thumb="item.picUrl" :thumb="item.picUrl"
:title="item.goodsName" :title="item.goodsName"
:desc="item.specifications.join(' ')" :desc="item.specifications.join(' ')"
@ -17,9 +18,9 @@
@handleDelete="handleDelete" @handleDelete="handleDelete"
@changeNum="changeNum" @changeNum="changeNum"
/> />
<Tabbar :amount="amount" :value="isAllSelect" @input="handleAllSelect" /> <Tabbar v-if="list && list.length > 0" :amount="amount" :value="isAllSelect" @input="handleAllSelect" />
<Skeleton v-if="isSkeletonShow" /> <Skeleton v-if="isSkeletonShow" />
<van-empty v-if="list && list.length <=0 " description="购物车里没有内容" /> <van-empty v-if="list && list.length <=0" description="小车大容量,喜欢的都加进来吧" />
</div> </div>
</template> </template>
@ -88,14 +89,18 @@ export default {
}, },
// all select // all select
handleAllSelect(value) { handleAllSelect(value) {
const data = this.list.map(item => { this.list.filter(item => {
return item.maxNum >= item.number
}).map(item => {
const data = { id: item.id, checked: value } const data = { id: item.id, checked: value }
updateCart(data).then(res => { updateCart(data).then(res => {
}).catch(e => {}) }).catch(e => {})
item.checked = value item.checked = value
return item return item
}) })
this.list = data this.list.forEach((item, i) => {
this.$set(this.list, i, item)
})
}, },
// item delete // item delete
handleDelete(idx) { handleDelete(idx) {
@ -105,12 +110,16 @@ export default {
duration: 0, duration: 0,
forbidClick: true forbidClick: true
}) })
deleteCart(idx).then(res => { deleteCart(idx).then(res => {
this.$toast.clear() this.$toast.clear()
this.$toast.success('删除成功') this.$toast.success('删除成功')
this.getList() const index = this.list.findIndex(item => item.id === idx)
}).catch(e => {}) this.list.splice(index, 1)
this.list.forEach((item, i) => {
this.$set(this.list, i, item)
})
console.log(this.list)
}).catch(e => { console.log(e) })
}, },
changeNum(id, num) { changeNum(id, num) {
let newval let newval

@ -3,11 +3,12 @@
<van-checkbox <van-checkbox
v-model="checked" v-model="checked"
icon-size="18px" icon-size="18px"
:disabled="invalid"
:checked-color="variables.theme" :checked-color="variables.theme"
style="padding:0 10px 0 16px" style="padding:0 10px 0 16px; background-color: white;"
/> />
<van-swipe-cell style="width:100%" :before-close="beforeClose"> <van-swipe-cell style="width:100%; background-color: white;" :before-close="beforeClose">
<van-card :tag="tag" :price="price" :desc="desc" :title="title" :thumb="thumb"> <van-card :price="price" :desc="desc" :title="title" :thumb="thumb">
<!-- <template #tags> <!-- <template #tags>
<van-tag <van-tag
v-for="(item,idx) in tags" v-for="(item,idx) in tags"
@ -19,10 +20,12 @@
</template> --> </template> -->
<template #footer> <template #footer>
<van-stepper <van-stepper
:value="value" v-if="!invalid"
:default-value="value" :value="num"
theme="round" :default-value="num"
button-size="20" button-size="26px"
min="1"
:max="maxNumber"
integer integer
async-change async-change
@change="onChange" @change="onChange"
@ -34,6 +37,7 @@
<template #right> <template #right>
<van-button square text="删除" type="danger" style="height:100%" /> <van-button square text="删除" type="danger" style="height:100%" />
</template> </template>
<div v-if="invalid" class="invalid"></div>
</van-swipe-cell> </van-swipe-cell>
</div> </div>
</template> </template>
@ -84,13 +88,18 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
maxNum: {
type: Number,
default: 0
},
isChecked: { isChecked: {
type: Boolean, type: Boolean,
default: false default: false
} }
}, },
data() { data() {
return { value: this.num } return {
}
}, },
computed: { computed: {
variables() { variables() {
@ -103,8 +112,27 @@ export default {
set(val) { set(val) {
this.$emit('input', { val, idx: this.index }) this.$emit('input', { val, idx: this.index })
} }
},
maxNumber() {
return this.maxNum > this.num ? this.maxNum : this.num
},
invalid() {
const valid = this.maxNum < this.num
return valid
} }
}, },
watch: {
num: {
handler(n, o) {
console.log('watch:' + n + ' ' + o)
}
},
deep: true,
immediate: true
},
mounted() {
console.log('id:' + this.index + ' maxNum:' + this.maxNum + ' curNum:' + this.num)
},
methods: { methods: {
// position // position
// instance SwipeCell // instance SwipeCell
@ -140,7 +168,7 @@ export default {
// value change // value change
changeNumber(this.index, value) changeNumber(this.index, value)
.then((res) => { .then((res) => {
this.value = value this.curNum = value
this.$emit('changeNum', this.index, Number(value)) this.$emit('changeNum', this.index, Number(value))
}) })
.catch() .catch()
@ -151,12 +179,31 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.card__item { .card__item {
position: relative;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
margin-bottom: 14px; background-color: #f9f8f8;
padding: 0px 10px 15px 10px;
.van-card__num { .van-card__num {
font-size: 16px; font-size: 16px;
} }
} }
.van-card__footer {
position: absolute;
top: 150px;
left: -16px;
}
.invalid {
position: absolute;
width: 120px;
height: 120px;
text-align: center;
line-height: 120px;
border-radius: 50%;
background-color: #554f4f;
color: white;
top: 40px;
left: 60px;
filter: opacity(80%);
}
</style> </style>

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<van-submit-bar :price="amount" button-text="" :disabled="disabled" class="submit-bar" @submit="onSubmit"> <van-submit-bar :price="amount" button-text="" :disabled="!canSubmit" class="submit-bar" @submit="onSubmit">
<van-checkbox v-model="checked" icon-size="18px" :checked-color="variables.theme"></van-checkbox> <van-checkbox v-model="checked" icon-size="18px" :checked-color="variables.theme"></van-checkbox>
</van-submit-bar> </van-submit-bar>
<div class="submit-bar-placeholder" style="width:100%;height:50px" /> <div class="submit-bar-placeholder" style="width:100%;height:50px" />
@ -22,7 +22,10 @@ export default {
} }
}, },
data() { data() {
return { disabled: false } return {
disabled: false,
allchecked: this.value
}
}, },
computed: { computed: {
variables() { variables() {
@ -30,16 +33,15 @@ export default {
}, },
checked: { checked: {
get() { get() {
return this.value return this.allchecked
}, },
set(val) { set(val) {
this.allchecked = val
this.$emit('input', val) this.$emit('input', val)
} }
} },
}, canSubmit() {
watch: { return this.amount > 0
amount(newVal) {
this.disabled = newVal <= 0
} }
}, },
methods: { methods: {

@ -4,7 +4,7 @@
<div class="main"> <div class="main">
<!-- <image-pic width="100%" fill="cover" :src="description" /> --> <!-- <image-pic width="100%" fill="cover" :src="description" /> -->
<div v-if="description" v-html="description" /> <div v-if="description" v-html="description" />
<div v-else style="text-align: center"> <div v-else style="text-align: center; padding: 15px 0px;">
<p>无详情</p> <p>无详情</p>
</div> </div>
</div> </div>

@ -122,13 +122,13 @@ export default {
params: { orderSn: this.orderSn, actualPrice: this.actualPrice } params: { orderSn: this.orderSn, actualPrice: this.actualPrice }
}) })
} catch (error) { } catch (error) {
console.log('下单失败', error)
setTimeout(async() => { setTimeout(async() => {
this.retryCount-- this.retryCount--
if (this.retryCount > 0) { if (this.retryCount > 0) {
await this.searchResult(this.orderSn) await this.searchResult(this.orderSn)
} else { } else {
this.$toast.fail('抱歉,创建订单失败!') console.log('下单失败', error)
this.$toast.fail(error.message)
} }
}, this.retryInterval) }, this.retryInterval)
} }

@ -24,9 +24,8 @@
:key="goodsIndex" :key="goodsIndex"
:title="goods.goodsName" :title="goods.goodsName"
:num="goods.number" :num="goods.number"
:price="goods.price" :price="goods.price | yuan"
:thumb="goods.picUrl" :thumb="goods.picUrl"
@click.native="toOrderDetail(goods.goodsId)"
> >
<div slot="desc"> <div slot="desc">
<div class="desc"> <div class="desc">
@ -38,15 +37,6 @@
>{{ spec }}</van-tag> >{{ spec }}</van-tag>
</div> </div>
</div> </div>
<template #footer>
<van-button
v-if="orderInfo.order_status == 401 && goods.comment == 0"
size="mini"
round
plain
@click.stop="commentGoods(goods.id, goods.goodsId)"
>去评价</van-button>
</template>
</van-card> </van-card>
</div> </div>
</div> </div>
@ -97,13 +87,17 @@ export default {
align-items: center; align-items: center;
} }
.order-detail { .order-detail {
padding: 1vw 2vh; padding: 10px 20px;
> div:nth-child(-n + 10) { > div:nth-child(-n + 10) {
margin-top: 1vh; margin-top: 1vh;
} }
van-card { van-card {
margin-top: 2vh; margin-top: 2vh;
} }
.van-card {
background-color: #f9f8f8;
padding: 15px 20px;
}
.van-card__header { .van-card__header {
text-align: right; text-align: right;
.van-button { .van-button {

@ -1,27 +1,11 @@
<template> <template>
<div class="search-container"> <div class="search-container">
<div class="search-nav-bar"> <nav-bar
<van-icon v-model="searchText"
size="16" :default-search="defaultSearch"
name="arrow-left" @handleSearch="handleSearch"
style="padding: 12px 0 12px 12px" @handleFocus="handleFocus"
@click="$router.back()" />
/>
<!--搜索栏-->
<van-search
v-model="searchText"
style="width: 100%"
show-action
placeholder="搜索商品名称"
@search="onSearch"
@focus="isResultShow = false"
@cancel="onCancel"
>
<template #action>
<div @click="onSearch"></div>
</template>
</van-search>
</div>
<search-words v-if="searchText == ''" :hot-list="hotList" /> <search-words v-if="searchText == ''" :hot-list="hotList" />
<!--联想建议--> <!--联想建议-->
<search-suggestion v-else-if="searchText" :search-text="searchText" /> <search-suggestion v-else-if="searchText" :search-text="searchText" />
@ -31,12 +15,14 @@
<script> <script>
import { getHotList } from '@/api/search' import { getHotList } from '@/api/search'
import SearchWords from './modules/Words' import SearchWords from './modules/Words'
import NavBar from './modules/NavBar'
import SearchSuggestion from './modules/Suggest' import SearchSuggestion from './modules/Suggest'
export default { export default {
name: 'SearchIndex', name: 'SearchIndex',
components: { components: {
SearchSuggestion, SearchSuggestion,
SearchWords SearchWords,
NavBar
}, },
data() { data() {
return { return {
@ -46,20 +32,10 @@ export default {
isResultShow: false // isResultShow: false //
} }
}, },
mounted() {
this.getHot()
},
methods: { methods: {
onSearch(val) {
//
this.isResultShow = true
this.$router.push({
path: '/search/list',
query: {
keyword: this.searchText
}
})
},
onCancel() {
this.$router.back()
},
getHot() { getHot() {
getHotList().then(res => { getHotList().then(res => {
this.hotList = res.map.data this.hotList = res.map.data
@ -74,15 +50,14 @@ export default {
keyword: value keyword: value
} }
}) })
},
handleFocus() {
} }
} }
} }
</script> </script>
<style lang="scss" scoped> <style scoped>
.search-nav-bar {
display: flex;
align-items: center;
}
</style> </style>

@ -1,7 +1,7 @@
<template> <template>
<div class="search-list"> <div class="search-list">
<nav-bar v-model="curSearchText" @handleSearch="handleSearch" /> <nav-bar v-model="searchText" @handleSearch="handleSearch" @handleFocus="handleFocus" />
<div v-if="searchText == curSearchText"> <div v-if="!focus">
<filter-bar @changeGoods="changeGoods($event)" /> <filter-bar @changeGoods="changeGoods($event)" />
<van-list <van-list
v-model="loading" v-model="loading"
@ -26,7 +26,7 @@
<van-empty v-if="list && list.length <=0 " description="没有搜索到商品" /> <van-empty v-if="list && list.length <=0 " description="没有搜索到商品" />
</div> </div>
<!--联想建议--> <!--联想建议-->
<search-suggestion v-else :search-text="curSearchText" /> <search-suggestion v-else :search-text="searchText" />
</div> </div>
</template> </template>
@ -48,7 +48,7 @@ export default {
data() { data() {
return { return {
searchText: '', searchText: '',
curSearchText: '', focus: false,
list: [], list: [],
pageSize: 10, pageSize: 10,
pageNum: 1, pageNum: 1,
@ -73,7 +73,6 @@ export default {
}) })
const { keyword } = this.$route.query const { keyword } = this.$route.query
this.searchText = keyword this.searchText = keyword
this.curSearchText = keyword
this.keyword = keyword this.keyword = keyword
this.getList() this.getList()
}, },
@ -112,6 +111,9 @@ export default {
} }
}) })
}, },
handleFocus() {
this.focus = true
},
changeGoods(val) { changeGoods(val) {
// //
if (val['search'] === 'filterNew') { if (val['search'] === 'filterNew') {

@ -2,8 +2,6 @@
<div class="search-filter"> <div class="search-filter">
<van-dropdown-menu style="flex:1"> <van-dropdown-menu style="flex:1">
<van-dropdown-item v-model="value1" :options="option1" @change="change1" /> <van-dropdown-item v-model="value1" :options="option1" @change="change1" />
<!-- <van-dropdown-item v-model="value2" :options="option2" />
<van-dropdown-item v-model="value3" :options="option3" /> -->
</van-dropdown-menu> </van-dropdown-menu>
<div class="filter" @click="chageSales"> <div class="filter" @click="chageSales">
<span style="font-size:15px;margin-right:2px">销量</span> <span style="font-size:15px;margin-right:2px">销量</span>

@ -13,6 +13,7 @@
show-action show-action
clearable clearable
autofocus autofocus
@focus="onFocus"
@search="onSearch" @search="onSearch"
@cancel="onCancel" @cancel="onCancel"
> >
@ -55,6 +56,9 @@ export default {
// } // }
// }, // },
methods: { methods: {
onFocus() {
this.$emit('handleFocus')
},
onSearch() { onSearch() {
const key = this.keyword.trim() || this.defaultSearch.trim() const key = this.keyword.trim() || this.defaultSearch.trim()
if (!key) { if (!key) {
@ -66,6 +70,7 @@ export default {
}, },
onCancel() { onCancel() {
this.value = '' this.value = ''
this.$router.back()
} }
} }
} }

@ -112,5 +112,16 @@ module.exports = {
// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
config.optimization.runtimeChunk('single') config.optimization.runtimeChunk('single')
}) })
},
css: {
loaderOptions: {
less: {
// 若 less-loader 版本小于 6.0,请移除 lessOptions 这一级,直接配置选项。
modifyVars: {
// 直接覆盖变量
'tabbar-item-icon-size': '24px'
}
}
}
} }
} }

Loading…
Cancel
Save