Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
wayn111 committed Apr 27, 2024
1 parent e6ee57e commit 79c4657
Show file tree
Hide file tree
Showing 26 changed files with 83 additions and 228 deletions.
4 changes: 2 additions & 2 deletions src/components/Tabbar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default {
methods: {
getCartGoodsCount() {
getCartGoodsCount().then(res => {
const { count } = res.map
this.count = count
const { data } = res
this.count = data
}).catch(e => {})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const actions = {
return new Promise((resolve, reject) => {
getAddress()
.then(res => {
const { data } = res.map
const { data } = res
commit('SET_ADDRESS_LIST', data)
resolve(data)
})
Expand Down
10 changes: 5 additions & 5 deletions src/store/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const actions = {
return new Promise((resolve, reject) => {
login({ mobile, password })
.then(res => {
const { token } = res.map
commit('SET_TOKEN', token)
setToken(token)
const { data } = res
commit('SET_TOKEN', data)
setToken(data)
resolve()
})
.catch(error => {
Expand Down Expand Up @@ -58,11 +58,11 @@ const actions = {
return new Promise((resolve, reject) => {
getInfo(state.token)
.then(res => {
const data = res.map
const data = res.data
if (!data) {
reject(new Error('获取基本信息失败,请重新登录'))
}
commit('SET_USER_INFO', data.info)
commit('SET_USER_INFO', data)
resolve(data)
})
.catch(error => {
Expand Down
20 changes: 9 additions & 11 deletions src/views/auth/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
<div class="login-container">
<div class="header">
<img class="header__logo" src="@/assets/logo4.png" alt="logo">
<!-- <p class="header__title">waynboot-mall</p> -->
</div>

<van-form class="form" @submit="onSubmit">
<van-field
v-model="form.mobile"
type="number"
type="text"
required
clearable
name="手机号"
label="手机号"
placeholder="请输入手机号"
name="登录用户"
label="登录用户"
placeholder="请输入登录用户名称"
:rules="[
{
validator: checkPhone,
Expand Down Expand Up @@ -64,7 +63,7 @@ export default {
data() {
return {
form: {
mobile: '',
username: '',
password: ''
},
loading: false
Expand Down Expand Up @@ -100,10 +99,10 @@ export default {
message: '登录成功',
duration: 1000,
onOpened: () => {
location.href = this.redirect
this.$router.push({ 'name': 'Home' })
},
onClose: () => {
location.href = this.redirect
this.$router.push({ 'name': 'Home' })
}
})
})
Expand All @@ -128,9 +127,8 @@ export default {
.header__logo {
display: block;
// width: 150px;
// height: 150px;
padding-top: 80px;
width: 100%;
// height: 800px;
}
.header__title {
font-size: 36px;
Expand Down
80 changes: 3 additions & 77 deletions src/views/auth/registry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,6 @@
]"
/>

<van-field
v-model="form.email"
type="text"
required
clearable
name="注册邮箱"
label="注册邮箱"
placeholder="请输入邮箱地址"
:rules="[
{
validator: checkEmail,
required: true,
message: '请输入正确的邮箱地址!',
},
]"
/>

<van-field
v-model="form.password"
type="password"
Expand Down Expand Up @@ -86,28 +69,6 @@
</template>
</van-field>

<van-field
v-model="form.emailCode"
type="text"
required
center
clearable
name="邮箱验证码"
label="邮箱验证码"
placeholder="请输入验证码"
:rules="[{ required: true, message: '请输入正确的邮箱验证码!' }]"
>
<van-button
slot="button"
size="small"
plain
type="info"
native-type="button"
:disabled="disabled"
@click.stop="getMailCode"
>{{ btnText }}</van-button>
</van-field>

<div style="margin: 36px">
<van-button
round
Expand All @@ -124,7 +85,7 @@

<script>
import variables from '@/styles/variables.scss'
import { getCaptcha, getMailCode } from '@/api/login'
import { getCaptcha } from '@/api/login'
import { setRegistry } from '@/api/user'
export default {
Expand All @@ -136,8 +97,6 @@ export default {
email: '',
password: '',
confirmPassword: '',
emailCode: '',
emailKey: '',
captchaCode: '',
captchaKey: ''
},
Expand All @@ -163,43 +122,10 @@ export default {
// 获取图形验证码
getCaptcha() {
getCaptcha().then((res) => {
this.captchaImg = res.map.captchaImg
this.form.captchaKey = res.map.captchaKey
this.captchaImg = res.data.image
this.form.captchaKey = res.data.key
})
},
// 获取邮箱验证码
getMailCode() {
const { email } = this.form
if (!email || !this.checkEmail(email)) {
this.$toast.fail('请先输入正确的邮箱地址')
return
}
const captchaKey = this.form.captchaKey
const captchaCode = this.form.captchaCode
const mobile = this.form.mobile
getMailCode({ email, captchaKey, captchaCode, mobile }).then((res) => {
this.form.emailKey = res.map.emailKey
this.disabled = true
this.totalCount = 60
this.interval = setInterval(() => {
this.totalCount--
if (this.totalCount === 0) {
clearInterval(this.interval)
this.disabled = false
}
}, 1000)
this.$notify({
type: 'success',
message: '邮箱验证码已发送',
duration: 2000
})
})
},
// 校检邮箱
checkEmail(email) {
const reg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return reg.test(email)
},
// 校检手机号
checkPhone(num) {
if (num === 123456789) return true
Expand Down
2 changes: 1 addition & 1 deletion src/views/cart/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default {
// get list
getList() {
getCartList().then(res => {
const { data } = res.map
const { data } = res
this.list = data
this.isSkeletonShow = false
})
Expand Down
4 changes: 2 additions & 2 deletions src/views/category/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default {
methods: {
getCategoryData() {
getCategoryData().then((res) => {
const { categoryList, currentCategory, subCategoryList } = res.map
const { categoryList, currentCategory, subCategoryList } = res.data
this.categoryList = categoryList
this.currentCategory = currentCategory
this.subCategoryList = subCategoryList
Expand All @@ -67,7 +67,7 @@ export default {
id: this.categoryList[this.active].id
}).then((res) => {
this.$toast.clear()
const { currentCategory, subCategoryList } = res.map
const { currentCategory, subCategoryList } = res.data
this.currentCategory = currentCategory
this.subCategoryList = subCategoryList
})
Expand Down
8 changes: 4 additions & 4 deletions src/views/detail/comment/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default {
methods: {
async getCommentTagNum() {
const res = await getCommentTagNum({ goodsId: this.goodsId })
const commentTagNum = res.map.commentTagNum
const commentTagNum = res.data
this.totalNum = commentTagNum.totalNum
this.tags = [
`全部`,
Expand All @@ -89,12 +89,12 @@ export default {
goodsId: this.goodsId
})
const {
map: { page }
data
} = res
this.list = [...this.list, ...page.records]
this.list = [...this.list, ...data.records]
this.loading = false
// 数据全部加载完成
if (page.records.length < this.pageSize) {
if (data.records.length < this.pageSize) {
this.finished = true
}
this.pageNum += 1
Expand Down
10 changes: 5 additions & 5 deletions src/views/detail/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ export default {
methods: {
getMallConfig() {
getMallConfig().then(res => {
const { map } = res
this.mallConfig = map
const { data } = res
this.mallConfig = data
})
},
getGoodsDetail() {
getDetail(this.goodsId).then((res) => {
const goods = res.map
const goods = res.data
this.attributes = goods.attributes
this.goods = goods
this.info = goods.info
Expand All @@ -136,7 +136,7 @@ export default {
async getCommentInfo() {
const res = await getCommentTagNum({ goodsId: this.goodsId })
const res1 = await getCommentList({ tagType: 0, goodsId: this.goodsId })
const commentTagNum = res.map.commentTagNum
const commentTagNum = res.data
let goodsRate = Math.ceil(
(commentTagNum.goodsNum / commentTagNum.totalNum) * 100
)
Expand All @@ -152,7 +152,7 @@ export default {
`有图(${commentTagNum.hasPictureNum})`
]
}
this.comment.list = res1.map.page.records.slice(0, 2)
this.comment.list = res1.data.records.slice(0, 2)
},
skuAdapter() {
const tree = this.setSkuTree()
Expand Down
2 changes: 1 addition & 1 deletion src/views/detail/modules/Tabbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default {
methods: {
getCartGoodsCount() {
getCartGoodsCount().then(res => {
const { count } = res.map
const { data } = res
this.count = count
}).catch(e => {})
},
Expand Down
8 changes: 4 additions & 4 deletions src/views/diamondGoodsList/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export default {
pageSize: this.pageSize,
diamondId: this.diamondId
}).then((res) => {
const data = res.map.goods
this.diamond = res.map.diamond
const data = res.data.goods
this.diamond = res.data.diamond
if (this.refreshing) {
this.list = data
this.refreshing = false
Expand All @@ -118,8 +118,8 @@ export default {
getCartGoodsCount() {
getCartGoodsCount()
.then((res) => {
const { count } = res.map
this.count = count
const { data } = res
this.count = data
})
.catch((e) => {})
},
Expand Down
2 changes: 1 addition & 1 deletion src/views/goodsComment/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default {
})
// 此时可以自行将文件上传至服务器
const uploadRes = await base64uploadFileList(fileList)
const urlList = uploadRes.map.fileList.map((item) => {
const urlList = uploadRes.data.map((item) => {
return item.url
})
this.picUrls = [...this.picUrls, ...urlList]
Expand Down
38 changes: 6 additions & 32 deletions src/views/home/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,37 +75,11 @@ export default {
methods: {
getHomeIndexData() {
getHomeData().then(res => {
const { map } = res
this.bannerList = map.bannerList
this.diamondList = map.diamondList
this.sessionList = [
{
'_id': '5f5b1ec83f8b304102b77e8d',
'img': 'https://m.360buyimg.com/babel/s750x300_jfs/t1/96501/1/14812/180805/5e69f6e2E65623863/c40c27c4ec520eef.jpg',
'title': '头号爆品、新书特卖专场',
'tagnum': 1000,
'discount': 3,
'time': 1699807149739
},
{
'_id': '5f5b1ec83f8b304102b77e90',
'img': 'https://m.360buyimg.com/babel/s1125x450_jfs/t1/98771/1/15620/172104/5e733babEe579fad9/d7d5e51a1f2975e8.jpg',
'title': '321阅读日、热门专场',
'tagnum': 9999,
'discount': 8,
'time': 1699907149739
},
{
'_id': '5f5b1ec83f8b304102b77e93',
'img': 'https://m.360buyimg.com/babel/s1125x450_jfs/t1/85360/22/15634/120107/5e733524E4883f099/c8c92ebd6112a76e.jpg',
'title': '电影学院,电影书籍专场特卖',
'tagnum': 666,
'discount': 5,
'time': 2699907149739
}
]
this.newGoodsList = map.newGoodsList
this.hotGoodsList = map.hotGoodsList
const { data } = res
this.bannerList = data.bannerList
this.diamondList = data.diamondList
this.newGoodsList = data.newGoodsList
this.hotGoodsList = data.hotGoodsList
this.isSkeletonShow = false
})
},
Expand All @@ -114,7 +88,7 @@ export default {
pageSize: this.pageSize,
pageNum: this.pageNum
}).then(res => {
const { map: { data }} = res
const { data } = res
this.goodsList = [...this.goodsList, ...data]
this.isLoading = false
if (data.length < this.pageSize && this.goodsList.length > 0) {
Expand Down
Loading

0 comments on commit 79c4657

Please sign in to comment.