Browse Source

小程序地址文本功能实现

h5_css
yanyan 3 years ago
parent
commit
876282e883
  1. 3
      manifest.json
  2. 32
      pages.json
  3. 12
      pages/my/my.vue
  4. 8
      store/user.js
  5. 88
      subpkg/address/address.vue
  6. 3
      subpkg/login/login.vue

3
manifest.json

@ -54,7 +54,8 @@
"setting" : {
"urlCheck" : false
},
"usingComponents" : true
"usingComponents" : true,
"requiredPrivateInfos": ["getLocation","onLocationChange","chooseLocation", "chooseAddress"]
},
"vueVersion" : "2"
}

32
pages.json

@ -17,7 +17,7 @@
"path": "pages/my/my",
"style": {
"navigationBarTitleText": "全民演练",
"enablePullDownRefresh": false,
"enablePullDownRefresh": true,
"navigationStyle": "custom"
}
},
@ -25,7 +25,7 @@
"path": "pages/knowledge/knowledge",
"style": {
"navigationBarTitleText": "全民演练",
"enablePullDownRefresh": false
"enablePullDownRefresh": true
}
}
],
@ -36,7 +36,7 @@
"style": {
"navigationBarTitleText": "场景演练",
"navigationBarTextStyle": "black",
"enablePullDownRefresh": false
"enablePullDownRefresh": true
}
},
{
@ -60,16 +60,40 @@
"style" :
{
"navigationBarTitleText" : "",
"enablePullDownRefresh" : false
"enablePullDownRefresh" : true
}
},
{
"path" : "medal/medal",
"style" :
{
"navigationBarTitleText" : "",
"enablePullDownRefresh" : true
}
},
{
"path" : "about/about",
"style" :
{
"navigationBarTitleText" : "",
"enablePullDownRefresh" : false
}
},
{
"path" : "agreement/agreement",
"style" :
{
"navigationBarTitleText" : "",
"enablePullDownRefresh" : false
}
},
{
"path" : "privacy/privacy",
"style" :
{
"navigationBarTitleText" : "",
"enablePullDownRefresh" : true
}
}]
}],
"globalStyle": {

12
pages/my/my.vue

@ -140,18 +140,12 @@
})
},
navClickHandler(item) {
//this.about();
if(item !== ""){
uni.navigateTo({
url:'/subpkg/addressNew/addressNew'
})
},
about() {
uni.showModal({
title: '关于',
content: '本程序后端使用Ruoyi实现,仅供学习使用,请勿使用于商业用途,如有问题,请联系QQ:123456',
showCancel: false
url: item.pagePath
})
}
}
},
components: {
tabbar

8
store/user.js

@ -5,6 +5,7 @@ export default {
// 数据
state: () => ({
address: JSON.parse(uni.getStorageSync('address') || '{}'),
userId: uni.getStorageSync('userId') || '',
token: uni.getStorageSync('token') || '',
// 用户的信息对象
userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
@ -36,9 +37,16 @@ export default {
state.token = token
this.commit('m_user/saveTokenToStorage')
},
updateUserId(state, userId) {
state.userId = userId
this.commit('m_user/saveUserIdToStorage')
},
saveTokenToStorage(state) {
uni.setStorageSync('token', state.token)
},
saveUserIdToStorage(state) {
uni.setStorageSync('userId', state.userId)
},
updateRedirectInfo(state, info) {
state.redirectInfo = info
console.log(state.redirectInfo)

88
subpkg/address/address.vue

@ -1,52 +1,54 @@
<template>
<view class="cart-container">
<!-- 选择收货地址的盒子 -->
<view class="address-choose-box" v-if="JSON.stringify(address) === '{}'">
<view class="address-choose-box">
<button type="primary" size="mini" class="btnChooseAddress" @click="chooseAddress">请选择收货地址+</button>
</view>
<!-- 渲染收货信息的盒子 -->
<view class="address-info-box" v-else @click="chooseAddress">
<!-- 底部的边框线 -->
<image src="/static/cart_border@2x.png" class="address-border"></image>
<!-- 循环渲染地址信息 -->
<view>
<uni-swipe-action>
<block v-for="(item, i) in addressList" :key="i">
<uni-swipe-action-item :options="options" @click="swipeItemClickHandler(item)">
<view class="address-info-box">
<view class="row1">
<view class="row1-left">
<view class="username">收货人:{{address.userName}}</view>
<view class="username">收货人:{{item.name}}</view>
</view>
<view class="row1-right">
<view class="phone">电话:{{address.telNumber}}</view>
<view class="phone">电话:{{item.mobile}}</view>
<uni-icons type="arrowright" size="16"></uni-icons>
</view>
</view>
<view class="row2">
<view class="row2-left">收货地址:</view>
<view class="row2-right">{{addstr}}</view>
<view class="row2-right">{{item.address}}</view>
</view>
</view>
<!-- 底部的边框线 -->
<image src="/static/cart_border@2x.png" class="address-border"></image>
<!-- 循环渲染地址信息 -->
<view>
<block v-for="(goods, i) in addressList" :key="i">
<view class="goods-item">
<!-- 左侧的盒子 -->
<view class="goods-item-left">
<radio :checked="goods.goods_state" color="#C00000" v-if="showRadio" @click="radioClickHandler"></radio>
<image :src="goods.goods_small_logo || defaultPic" class="goods-pic"></image>
</uni-swipe-action-item>
</block>
</uni-swipe-action>
<!-- <block v-for="(item, i) in addressList" :key="i">
<view class="address-info-box">
<view class="row1">
<view class="row1-left">
<view class="username">收货人:{{item.name}}</view>
</view>
<view class="row1-right">
<view class="phone">电话:{{item.mobile}}</view>
<uni-icons type="arrowright" size="16"></uni-icons>
</view>
<!-- 右侧的盒子 -->
<view class="goods-item-right">
<!-- 商品的名字 -->
<view class="goods-name">{{goods.goods_name}}</view>
<view class="goods-info-box">
<view class="goods-price"><bV> </bV>{{goods.goods_price | tofixed}}</view>
<uni-number-box :min="1" :value="goods.goods_count" v-if="showNum" @change="numChangeHandler"></uni-number-box>
</view>
<view class="row2">
<view class="row2-left">收货地址:</view>
<view class="row2-right">{{item.address}}</view>
</view>
</view>
</block>
</block> -->
</view>
</view>
</template>
@ -57,17 +59,39 @@
export default {
data() {
return {
address: {},
addressList:[{"goods_name":"111"}]
addressList:[]
};
},
onLoad() {
this.initAddress();
},
methods: {
...mapMutations('m_user', ['updateAddress']),
async initAddress(){
const {
data: res
} = await uni.$http.post('/small/project/address/listAll',{userId:this.userId})
if (!res.success) return uni.$showMsg()
this.addressList = res.data;
},
async chooseAddress() {
const [err, succ] = await uni.chooseAddress().catch(err => err)
if (err === null && succ.errMsg === 'chooseAddress:ok') {
// this.address = succ
this.updateAddress(succ)
const addressObj = {
userId: this.userId,
name: succ.userName,
mobile: succ.telNumber,
address: succ.provinceName + succ.cityName + succ.countyName + succ.detailInfo
}
this.addressList.push(addressObj)
const {
data: res
} = await uni.$http.post('/small/project/address/add',addressObj)
if (!res.success) return uni.$showMsg()
this.initAddress();
}
if (err && (err.errMsg === 'chooseAddress:fail auth deny' || err.errMsg === 'chooseAddress:fail authorize no response')) {
@ -97,7 +121,7 @@
}
},
computed: {
...mapState('m_user', ['address']),
...mapState('m_user', ['address','userId']),
...mapGetters('m_user', ['addstr'])
}
}

3
subpkg/login/login.vue

@ -19,7 +19,7 @@
...mapState('m_user', ['redirectInfo'])
},
methods:{
...mapMutations('m_user', ['updateUserInfo', 'updateToken', 'updateRedirectInfo']),
...mapMutations('m_user', ['updateUserInfo', 'updateToken', 'updateUserId', 'updateRedirectInfo']),
getUserInfo(e) {
console.log(e)
@ -56,6 +56,7 @@
// 直接把 token 保存到 vuex 中
this.updateToken(loginResult.token)
this.updateUserId(loginResult.userId)
uni.switchTab({
url: '/pages/index/index'
})

Loading…
Cancel
Save