Commit af43e5d9 authored by June's avatar June

feature

parent c047352c
<script> <script>
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
import { checkLoginStatus } from '@/apis/user.js'
import { login_wx } from '@/utils/modules/login.js'
export default { export default {
onLaunch: function() { onLaunch: async function() {
this.checkUpdate() this.setSystemInfo() // 获取系统信息
this.setSystemInfo() this.setLocation() // 获取经纬度
this.setLocation() this.setMenuButtonInfo() // 获取胶囊信息
this.setMenuButtonInfo() this.checkUpdate() // 检查更新
// await login_wx()
checkLoginStatus() // 检查登录状态
.then(res => {
console.log(res)
if(res.status) {
this.setLoginStatus(true)
this.setCount()
} else {
this.setLoginStatus(false)
}
})
.catch(err => console.log(err))
}, },
methods: { methods: {
...mapActions('systemInfo', ['setSystemInfo', 'setMenuButtonInfo']), ...mapActions('systemInfo', ['setSystemInfo', 'setMenuButtonInfo']),
...mapActions('user', ['setLocation']), ...mapActions('user', ['setLocation', 'setLoginStatus']),
...mapActions('cart', ['setCount']),
// 检查更新 // 检查更新
checkUpdate() { checkUpdate() {
if (wx.canIUse('getUpdateManager')) { if (wx.canIUse('getUpdateManager')) {
...@@ -34,7 +48,8 @@ export default { ...@@ -34,7 +48,8 @@ export default {
this.$toast({title: "更新失败,请检查您的网络是否正常"}) this.$toast({title: "更新失败,请检查您的网络是否正常"})
}) })
} }
} }
} }
} }
......
...@@ -2,6 +2,16 @@ ...@@ -2,6 +2,16 @@
import { request } from "@/lib/service" import { request } from "@/lib/service"
import { baseUrl } from '@/config' import { baseUrl } from '@/config'
/**
* @desc 获取购物车数量
*/
export function cartCount() {
return request({
url: `${baseUrl}/wxxcx/cartCount.htm`,
method: 'post'
})
}
/** /**
* @desc 获取购物车列表 * @desc 获取购物车列表
*/ */
......
...@@ -38,3 +38,18 @@ export function goodDetail(params) { ...@@ -38,3 +38,18 @@ export function goodDetail(params) {
}) })
} }
/**
* @desc 商品规格选择接口
* goods_id
* shop_id
* sale_type
*/
export function goodsSku(goods_id, shop_id, sale_type = 0) {
return request({
url: `${baseUrl}/wxxcx/goodsSku.htm`,
method: 'post',
data: {
goods_id, shop_id, sale_type
}
})
}
...@@ -3,23 +3,47 @@ import { request } from "@/lib/service" ...@@ -3,23 +3,47 @@ import { request } from "@/lib/service"
import { baseUrl } from '@/config' // 将请求的baseUrl写这里,为了开发时调试请求地址 import { baseUrl } from '@/config' // 将请求的baseUrl写这里,为了开发时调试请求地址
const RSA = require('@/utils/wx_rsa.js') const RSA = require('@/utils/wx_rsa.js')
import { publicKey } from '@/config/index.js' import { publicKey } from '@/config/index.js'
/** /**
* @desc 检查登录态 * @desc 检查登录态
*/ */
export function checkLogin() { export function checkLoginStatus() {
return request({
url: `${baseUrl}/wxxcx/isLogin.htm`,
method: 'post',
needMask: true
})
}
/**
* 检查服务器时间
*/
export function checkLoginTime() {
return request({ return request({
url: `${baseUrl}/wxxcx/getFwqTime.htm`, url: `${baseUrl}/wxxcx/getFwqTime.htm`,
method: 'post' method: 'post'
}) })
} }
/**
* @desc 微信登录 wx.login 获取openid unionid等信息
* @param { String } code
*/
export function wxLogin(code) {
return request({
url: `${baseUrl}/wxxcx/getInfo.htm`,
data: {
js_code: code
}
})
}
/** /**
* @desc 静默登录 * @desc 静默登录
* @param { Number } userPhone * @param { Number } userPhone
* @param { String } time * @param { String } time
*/ */
export function slelentLogin(userPhone, time) { export function slelentLogin(userPhone, time) {
console.log(userPhone, time)
const encrypt_rsa = RSA.KEYUTIL.getKey(publicKey) const encrypt_rsa = RSA.KEYUTIL.getKey(publicKey)
return request({ return request({
url: `${baseUrl}/wxxcx/silentLogin.htm`, url: `${baseUrl}/wxxcx/silentLogin.htm`,
...@@ -32,23 +56,39 @@ export function slelentLogin(userPhone, time) { ...@@ -32,23 +56,39 @@ export function slelentLogin(userPhone, time) {
} }
/** /**
* @desc 登录 * @desc 退出登录
*/ */
export function login() { export function logout() {
return request({ return request({
url: `${baseUrl}/a` url: `${baseUrl}/wxxcx/loginOut.htm`,
method: 'post',
needMask: true
}) })
} }
/** /**
* @desc 注册 * @desc 注册
* @param {Object} params
*
* lgtype 必填 登录方式:1微信登录 2短信验证码登录 3账号密码登录
* user 用户名(lgtype!=1时必填)
* pwd 登录密码(lgtype=3时必填)
* yzm 登录验证码(lgtype=2时必填
* encryptedData 加密信息(lgtype=1时必填)
* iv 加密算法的初始向量(lgtype=1时必填)
* session_key 会话密钥(lgtype=1时必填)
*/ */
export function register() { export function register(params) {
return request({ return request({
url:`${baseUrl}/a` url: `${baseUrl}/wxxcx/login.htm`,
method: 'post',
data: params
}) })
} }
/** /**
* @desc 获取手机验证码 * @desc 获取手机验证码
*/ */
......
<template>
<uni-popup ref="goodsPopup" type="bottom">
<view class="wrapper p-2 w-100">
<view v-if="!showSku">
<image style="width: 180rpx;height: 180rpx;" src="../../static/images/common/loading.gif" mode="widthFix"></image>
</view>
<view v-else>1111</view>
</view>
</uni-popup>
</template>
<script>
import uniPopup from '@/components/uni-popup/index.vue'
import { goodsSku } from '@/apis/goods.js'
export default {
name: 'goods-popup',
props: {
goods_id: {
type: Number | String,
default: 0
}
},
data() {
return {
showSku: false,
detail: null
}
},
components: {
uniPopup
},
methods: {
async show(e) {
try{
console.log(e)
const res = await goodsSku(e.goods_id, e.shop_id)
console.log(res)
setTimeout(() => {
this.showSku = true
}, 2000)
this.$refs.goodsPopup.open()
}catch(e){
console.log(e)
this.$toast({title: e.msg || '程序错误'})
}
},
hide() {
this.$refs.goodsPopup.close()
this.showSku = false
this.detail = null
}
}
}
</script>
<style lang="scss" scoped>
.wrapper {
background-color: #fff;
}
</style>
...@@ -2,7 +2,8 @@ import Toast from "../toast/index.js" ...@@ -2,7 +2,8 @@ import Toast from "../toast/index.js"
import { isObeject, isFunction } from "@/utils/types.js" import { isObeject, isFunction } from "@/utils/types.js"
import Validator from "@/utils/validate.js" import Validator from "@/utils/validate.js"
import { login_slilen } from '@/utils/modules/login.js' import { login_slilen } from '@/utils/modules/login.js'
import store from '@/store/index.js' import store from '@/store/index.js'
/** /**
* @desc 请求 所有的状态码都在这里处理 * @desc 请求 所有的状态码都在这里处理
* @param { Object } options 参考uni.request参数说明 * @param { Object } options 参考uni.request参数说明
...@@ -30,57 +31,75 @@ export function request (options) { ...@@ -30,57 +31,75 @@ export function request (options) {
...options, ...options,
header: { header: {
'content-type': 'application/x-www-form-urlencoded', 'content-type': 'application/x-www-form-urlencoded',
'cookie': 'JSESSIONID=aaaH_PdwNLO-Oan2L7QNx; path=/' 'cookie': store.state.user.cookieKey
}, },
success: res => { success: async res => {
const statusCode = res.statusCode try{
// console.log(statusCode) const statusCode = res.statusCode
switch(statusCode) { // console.log(statusCode)
case 200: switch(statusCode) {
options.successCb && typeof options.successCb === 'function' && options.successCb() case 200:
// 处理某些接口返回String类型的数据 options.successCb && typeof options.successCb === 'function' && options.successCb()
const data = (res.data && typeof res.data === 'string') ? JSON.parse(res.data) : res.data // 处理某些接口返回String类型的数据
const status = data.code const data = (res.data && typeof res.data === 'string') ? JSON.parse(res.data) : res.data
switch(status) { const status = data.code
case 10: switch(status) {
resolve({ case 10:
status: true, resolve({
data: res.data.list || res.data.data, status: true,
res: res.data, data: res.data.list || res.data.data,
msg: data.rep_msg res: res.data,
}) msg: data.rep_msg
break; })
case -3: break;
login_slilen() case -1:
// return Toast({title: 'login', cb: () => { resolve({
// uni.navigateTo({ status: true,
// url: '/pages/login/index.vue' data: res.data.list || res.data.data,
// }) res: res.data,
// }}) msg: data.rep_msg
break; })
default: break;
Toast({title: data.rep_msg}) case -3:
resolve({ const loginRes = await login_slilen()
status: false, console.log('刷新登录 重新执行上一次请求=======')
code: status, // 正常不返回为了好找 后端调试 -1 => 业务错误(一般失败情况返回此项);-2 => 系统异常; -3 => 请先登录; -4 => 请求失败; -10 => 签名失败 if(loginRes) { // 重新执行上一次的操作
data: data.list, const againRes = await request(options)
res: res.data.list || res.data.data, resolve({
msg: data.rep_msg status: true,
}) data: againRes.list || againRes.data,
break; res: againRes.res,
} msg: againRes.msg
})
break; }
case 404: break;
return Toast({title: '请求路径不存在'}) default:
break; Toast({title: data.rep_msg})
case 500: resolve({
return Toast({title: '服务器错误'}) status: false,
break; // 这里的break可以不写,不会执行到。return直接退出函数了 code: status, // 正常不返回为了好找 后端调试 -1 => 业务错误(一般失败情况返回此项);-2 => 系统异常; -3 => 请先登录; -4 => 请求失败; -10 => 签名失败
default: data: data.list,
Toast({title: '网络请求失败'}) res: res.data.list || res.data.data,
return msg: data.rep_msg
break; })
break;
}
break;
case 404:
return Toast({title: '请求路径不存在'})
break;
case 500:
return Toast({title: '服务器错误'})
break; // 这里的break可以不写,不会执行到。return直接退出函数了
default:
Toast({title: '网络请求失败'})
return
break;
}
}catch(e){
console.log(e)
Toast({title: e.msg || '程序请求错误'})
} }
}, },
fail: err => { fail: err => {
......
...@@ -6,7 +6,9 @@ import "@/utils/vue_extend.js" // 常用方法 ...@@ -6,7 +6,9 @@ import "@/utils/vue_extend.js" // 常用方法
// 全局组件 // 全局组件
import emptyView from '@/components/empty-view/index.vue' import emptyView from '@/components/empty-view/index.vue'
import uniPopup from '@/components/uni-popup/index.vue'
Vue.component('empty-view', emptyView) Vue.component('empty-view', emptyView)
Vue.component('uni-popup', uniPopup)
Vue.config.productionTip = false Vue.config.productionTip = false
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
"quickapp" : {}, "quickapp" : {},
/* 小程序特有相关 */ /* 小程序特有相关 */
"mp-weixin" : { "mp-weixin" : {
"appid" : "wx445b225e03ee51aa", "appid" : "wxd170058f4ad8fecd",
"setting" : { "setting" : {
"urlCheck" : false, "urlCheck" : false,
"es6" : true, "es6" : true,
......
...@@ -4,10 +4,35 @@ ...@@ -4,10 +4,35 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"charenc": {
"version": "0.0.2",
"resolved": "https://registry.npm.taobao.org/charenc/download/charenc-0.0.2.tgz",
"integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc="
},
"crypt": {
"version": "0.0.2",
"resolved": "https://registry.nlark.com/crypt/download/crypt-0.0.2.tgz",
"integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs="
},
"dayjs": { "dayjs": {
"version": "1.10.5", "version": "1.10.5",
"resolved": "https://registry.nlark.com/dayjs/download/dayjs-1.10.5.tgz?cache=0&sync_timestamp=1622012259636&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fdayjs%2Fdownload%2Fdayjs-1.10.5.tgz", "resolved": "https://registry.nlark.com/dayjs/download/dayjs-1.10.5.tgz?cache=0&sync_timestamp=1622012259636&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fdayjs%2Fdownload%2Fdayjs-1.10.5.tgz",
"integrity": "sha1-VgDfRUj8JFOz8WPrsqu+llzPuYY=" "integrity": "sha1-VgDfRUj8JFOz8WPrsqu+llzPuYY="
},
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npm.taobao.org/is-buffer/download/is-buffer-1.1.6.tgz?cache=0&sync_timestamp=1604429452232&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fis-buffer%2Fdownload%2Fis-buffer-1.1.6.tgz",
"integrity": "sha1-76ouqdqg16suoTqXsritUf776L4="
},
"md5": {
"version": "2.3.0",
"resolved": "https://registry.npm.taobao.org/md5/download/md5-2.3.0.tgz",
"integrity": "sha1-w9qaaq46MLRreww0m4exENw72k8=",
"requires": {
"charenc": "0.0.2",
"crypt": "0.0.2",
"is-buffer": "~1.1.6"
}
} }
} }
} }
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"dayjs": "^1.10.5" "dayjs": "^1.10.5",
"md5": "^2.3.0"
} }
} }
...@@ -66,17 +66,17 @@ ...@@ -66,17 +66,17 @@
"root": "subPages", "root": "subPages",
"pages": [ "pages": [
{ {
"path": "test/index", "path": "userManage/index",
"style": { "style": {
"navigationBarTitleText": "test" "navigationBarTitleText": "账号管理"
} }
} }
] ]
}], }],
"preloadRule": { "preloadRule": {
"subPages/test/index": { "pages/home/index": {
"network": "all", "network": "all",
"packages": ["__APP__"] "packages": ["subPages"]
} }
}, },
"globalStyle": { "globalStyle": {
......
<template> <template>
<view class="cart-wrap"> <view class="cart-wrap">
<template v-if="cartList.length === 0"> <view v-if="!isLogin">
<empty-view <button type="default" @click="handleLogin">登录</button>
iconSrc="../../static/images/common/icon_nothing.png" </view>
text="购物车为空" <view v-else>
/> <template v-if="cartList.length === 0">
</template> <empty-view
iconSrc="../../static/images/common/icon_nothing.png"
<template v-else> text="购物车为空"
<view class="list-wrap W-100"> />
<view </template>
class="list-item"
v-for="(item, index) in cartList" <template v-else>
:key="index" <view class="list-wrap W-100">
@click="handleCartItem(index, item)" <view
> class="list-item"
<view> v-for="(item, index) in cartList"
<text>{{item.checked ? '选中' : '未选中'}}</text> <text>{{item.price}}</text> :key="index"
</view> @click="handleCartItem(index, item)"
<view style="width: 240rpx;height: 64rpx;"> >
<input-number <view>
:index="index" <text>{{item.checked ? '选中' : '未选中'}}</text> <text>{{item.price}}</text>
:value="item.counts" </view>
@change="numberChange" <view style="width: 240rpx;height: 64rpx;">
/> <input-number
:index="index"
:value="item.counts"
@change="numberChange"
/>
</view>
</view> </view>
</view> </view>
</view> </template>
</template>
<view>总价:{{totalPrice}}</view>
<view>总价:{{totalPrice}}</view> </view>
</view> </view>
</template> </template>
<script> <script>
import inputNumber from '@/components/inputNumber/index.vue' import inputNumber from '@/components/inputNumber/index.vue'
import { mapState } from 'vuex'
export default { export default {
data() { data() {
return { return {
...@@ -70,6 +77,9 @@ export default { ...@@ -70,6 +77,9 @@ export default {
}, },
computed: { computed: {
...mapState({
isLogin: state => state.user.isLogin
}),
// 总价 // 总价
totalPrice() { totalPrice() {
return this.cartList.filter(item => item.checked).reduce((pre, cur) => { return this.cartList.filter(item => item.checked).reduce((pre, cur) => {
...@@ -79,6 +89,12 @@ export default { ...@@ -79,6 +89,12 @@ export default {
}, },
methods: { methods: {
handleLogin() {
uni.navigateTo({
url: '/pages/login/index'
})
},
handleCartItem(index, item) { handleCartItem(index, item) {
item.checked = !item.checked item.checked = !item.checked
this.$set(this.cartList, index, item) this.$set(this.cartList, index, item)
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
<script> <script>
import leftMenuButton from './components/left-menuButton.vue' import leftMenuButton from './components/left-menuButton.vue'
import uParse from '@/components/parse/parse.vue' import uParse from '@/components/parse/parse.vue'
import { goodDetail } from '@/apis/goods.js' import { goodDetail } from '@/apis/goods.js'
import { imgUrl } from '@/config/index.js' import { imgUrl } from '@/config/index.js'
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
> >
<image class="goods_cover w-100" :src="arr[item]" mode="aspectFit"></image> <image class="goods_cover w-100" :src="arr[item]" mode="aspectFit"></image>
<view> <view>
<view @click.stop="purchase(index)">购物ICON</view> <view @click.stop="purchase(item)">购物ICON</view>
</view> </view>
</view> </view>
</view> </view>
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
</template> </template>
<script> <script>
export default { export default {
props: { props: {
title: { title: {
...@@ -40,8 +41,13 @@ export default { ...@@ -40,8 +41,13 @@ export default {
url: `/pages/goods/detail?goods_id=9192&shop_id=101120&agent_id=0` url: `/pages/goods/detail?goods_id=9192&shop_id=101120&agent_id=0`
}) })
}, },
purchase(e) { purchase(item) {
// this.$me console.log(item)
this.$emit('purchase', {
goods_id: 7344,
sale_type: 0,
shop_id: 100737
})
} }
} }
} }
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
</view> </view>
</view> </view>
<button type="default" @click="handleLogout">退出登录</button>
<button type="default" @click="handleCart">购物车请求</button>
<!-- content --> <!-- content -->
<template v-if="isOverdue"> <template v-if="isOverdue">
<view class="w-100 content-wrap flex flex-column j-center a-center"> <view class="w-100 content-wrap flex flex-column j-center a-center">
...@@ -44,16 +47,18 @@ ...@@ -44,16 +47,18 @@
</view> </view>
<view> <view>
<goods-module title="热销111" :list="module1" /> <goods-module title="热销111" :list="module1" @purchase="purchase" />
</view> </view>
</view> </view>
</template> </template>
<!-- <view class="test" @click="login">登录</view> <!-- <view class="test" @click="login">登录</view>
<!-- <city-picker @confirmCity="confirmCity"></city-picker> --> <!-- <city-picker @confirmCity="confirmCity"></city-picker> -->
<!-- <navigator url="/pages/goods/detail">详情页</navigator> --> <!-- <navigator url="/pages/goods/detail">详情页</navigator> -->
<uni-popup type="bottom">
<view>{{select_goods.test}}</view>
</uni-popup> <goods-popup ref="goodsPopup"></goods-popup>
<button type="default" open-type="share" id="share"></button> <button type="default" open-type="share" id="share"></button>
</view> </view>
</template> </template>
...@@ -61,12 +66,15 @@ ...@@ -61,12 +66,15 @@
<script> <script>
import searchBar from '@/components/search-bar/index.vue' import searchBar from '@/components/search-bar/index.vue'
import goodsModule from './components/goods-module.vue' import goodsModule from './components/goods-module.vue'
import uniPopup from '@/components/uni-popup/index.vue' import goodsPopup from '@/components/goods-popup/index.vue'
import cityPicker from '@/components/city-picker/index.vue' import cityPicker from '@/components/city-picker/index.vue'
import { mapState } from 'vuex' import { mapState, mapActions } from 'vuex'
import { checkLogin } from '@/utils/common.js' import { checkLogin } from '@/utils/common.js'
import { logout } from '@/apis/user.js'
export default { export default {
data() { data() {
return { return {
...@@ -77,7 +85,8 @@ export default { ...@@ -77,7 +85,8 @@ export default {
components: { components: {
searchBar, searchBar,
goodsModule, goodsModule,
uniPopup, goodsPopup,
cityPicker cityPicker
}, },
...@@ -92,12 +101,9 @@ export default { ...@@ -92,12 +101,9 @@ export default {
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
title: '测试店铺' title: '测试店铺'
}) })
uni.$on('purchase', e => {
console.log(e)
})
this.$once('hook:beforeDe')
}, },
onShareAppMessage() { onShareAppMessage() {
return { return {
title: '分享title' title: '分享title'
...@@ -105,7 +111,20 @@ export default { ...@@ -105,7 +111,20 @@ export default {
}, },
methods: { methods: {
...mapActions('cart', ['setCount']),
handleLogout() {
logout()
.then(res => console.log(res))
},
handleCart() {
this.setCount()
},
purchase(e) {
this.$refs.goodsPopup.show(e)
},
handleMenu(type) { handleMenu(type) {
checkLogin(() => { checkLogin(() => {
switch(type) { switch(type) {
......
import Validator from "@/utils/validate.js" import Validator from "@/utils/validate.js"
import { register } from '@/apis/user.js'
function smsValidate() { function smsValidate() {
const smsValidator = new Validator() const smsValidator = new Validator()
...@@ -17,7 +17,17 @@ function accoutValidate() { ...@@ -17,7 +17,17 @@ function accoutValidate() {
return smsValidator.validate() return smsValidator.validate()
} }
async function registerCommon(params) {
try{
const res = await register(params)
console.log(res)
}catch(e){
this.$toast({title: e.msg || '程序错误'})
}
}
export default { export default {
smsValidate, smsValidate,
accoutValidate accoutValidate,
registerCommon
} }
\ No newline at end of file
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
/> />
</view> </view>
<view v-show="login_type === 'smsLogin'"> <view v-show="form.lgtype === 2">
<input <input
type="text" type="text"
placeholder="请输入验证码" placeholder="请输入验证码"
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<view>SMS</view> <view>SMS</view>
</view> </view>
<view v-show="login_type === 'accoutLogin'"> <view v-show="form.lgtype === 3">
<input <input
type="password" type="password"
placeholder="请输入密码" placeholder="请输入密码"
...@@ -29,9 +29,9 @@ ...@@ -29,9 +29,9 @@
</view> </view>
<view> <view>
<button type="default" @click="handleLogin('smsLogin')">短信验证码注册登录</button> <button type="default" @click="handleLogin(2)">短信验证码注册登录</button>
<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信快捷登录</button> <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信快捷登录</button>
<button type="default" @click="handleLogin('accoutLogin')">密码登录</button> <button type="default" @click="handleLogin(3)">密码登录</button>
</view> </view>
...@@ -40,20 +40,26 @@ ...@@ -40,20 +40,26 @@
<script> <script>
import loginCommon from './common.js' import loginCommon from './common.js'
// import uniPopup from '@/components/uni-popup/index.vue'
import { timerFn } from '@/utils/common.js' import { timerFn } from '@/utils/common.js'
import { mapState } from 'vuex'
export default { export default {
data() { data() {
return { return {
login_type: "smsLogin", // smsLogin wxLogin accoutLogin login_type: "smsLogin", // smsLogin wxLogin accoutLogin
form: { form: {
lgtype: 2, // 1微信登录 2短信验证码登录 3账号密码登录
phone: null, phone: null,
smsCode: null, smsCode: null,
password: null password: null
} }
} }
}, },
computed: {
...mapState({
session_key: state => state.user.session_key
})
},
// components: { // components: {
// uniPopup // uniPopup
// }, // },
...@@ -66,8 +72,7 @@ export default { ...@@ -66,8 +72,7 @@ export default {
}, },
handleLogin(type) { handleLogin(type) {
if(type !== this.login_type) return this.login_type = type if(type !== this.form.lgtype) return this.$set(this.form, 'lgtype', type)
console.log('-----------------------')
switch (type) { switch (type) {
case 'smsLogin': case 'smsLogin':
const smsValidaErr = this.smsValidate() const smsValidaErr = this.smsValidate()
...@@ -88,9 +93,15 @@ export default { ...@@ -88,9 +93,15 @@ export default {
getPhoneNumber (e) { getPhoneNumber (e) {
console.log(e.detail.errMsg) if(e.detail.errMsg === 'getPhoneNumber:fail user deny') return
console.log(e.detail.iv) const { iv, encryptedData } = e.detail
console.log(e.detail.encryptedData) console.log(iv, encryptedData)
this.registerCommon({
lgtype: 1,
encryptedData,
iv,
session_key: this.session_key
})
}, },
......
<template> <template>
<view class="w-100"> <view class="w-100">
<!-- userInfo --> <!-- userInfo -->
<view class="user-wrap flex j-start a-center w-100"> <view class="user-wrap flex j-start a-center w-100" @click="handleAvatar">
<template v-if="token"> <template v-if="isLogin">
<open-data class="avatar mr-2" type="userAvatarUrl"></open-data> <open-data class="avatar mr-2" type="userAvatarUrl"></open-data>
<open-data type="userNickName" lang="zh_CN"></open-data> <open-data type="userNickName" lang="zh_CN"></open-data>
</template> </template>
...@@ -76,7 +76,7 @@ export default { ...@@ -76,7 +76,7 @@ export default {
}, },
computed: { computed: {
...mapState({ ...mapState({
token: state => state.user.token isLogin: state => state.user.isLogin
}) })
}, },
methods: { methods: {
...@@ -99,6 +99,18 @@ export default { ...@@ -99,6 +99,18 @@ export default {
}) })
}, },
handleAvatar() {
if(this.isLogin) {
uni.navigateTo({
url: '/subPages/userManage/index'
})
} else {
uni.navigateTo({
url: '/pages/login/index'
})
}
},
// 拨打电话 // 拨打电话
phoneCall() { phoneCall() {
checkLogin(() => { checkLogin(() => {
......
import { cartCount } from "@/apis/carts.js"
const state = {
cart_count: 0
}
const mutations = {
SETCOUNT(state, count) {
state.cart_count = count
}
}
const actions = {
setCount: async ({ commit }) => {
const res = await cartCount()
const count = res.res.count
console.log('vuex actions success ==========================================')
if(res.status && count > 0) {
commit('SETCOUNT', count)
uni.setTabBarBadge({
index: 2,
text: count > 99 ? '99+' : JSON.stringify(count)
})
} else {
wx.removeTabBarBadge({index: 2})
}
}
}
export default {
namespaced: true,
state,
mutations,
actions
}
\ No newline at end of file
...@@ -2,13 +2,20 @@ import { getStorage, setStorage, removeStorage } from '@/lib/storage' ...@@ -2,13 +2,20 @@ import { getStorage, setStorage, removeStorage } from '@/lib/storage'
// import store from '@/store/index.js' // import store from '@/store/index.js'
const state = { const state = {
token: '111', isLogin: true,
openid: null,
unionid: null,
session_key: '',
cookieKey: 'JSESSIONID=aaaD4X0GrEplMbVRPm5Nx; path=/',
isOverdue: false, // 服务是否过期 isOverdue: false, // 服务是否过期
userInfo: null, userInfo: null,
location: {} location: {}
} }
const mutations = { const mutations = {
SETLOGINSTATUS(state, status) {
state.isLogin = status
},
SETTOKEN(state, token){ SETTOKEN(state, token){
state.token = token state.token = token
}, },
...@@ -22,6 +29,9 @@ const mutations = { ...@@ -22,6 +29,9 @@ const mutations = {
} }
const actions = { const actions = {
setLoginStatus: ({commit}, status) => {
commit('SETLOGINSTATUS', status)
},
setToken: ({commit}, token) => { setToken: ({commit}, token) => {
commit('SETTOKEN', token) commit('SETTOKEN', token)
setStorage('token',token) setStorage('token',token)
......
<template>
<view class="w-100">
<view class="w-100 flex j-between a-center">
<view>头像</view>
<image
class="avatar"
src="../../static/images/common/icon_nothing.png"
mode="aspectFit"
@click="changeAvatar"
/>
</view>
<view @click="handleLogout">退出登录</view>
</view>
</template>
<script>
export default {
methods: {
changeAvatar(e) {
uni.chooseImage({
count: 1,
success: res => console.log(res)
})
}
}
}
</script>
<style lang="scss" scoped>
.avatar {
width: 180rpx;
height: 180rpx;
}
</style>
import { checkLogin, slelentLogin } from '@/apis/user.js' import { checkLoginTime, slelentLogin, wxLogin } from '@/apis/user.js'
import store from '@/store/index.js' import store from '@/store/index.js'
export async function login_slilen() { export async function login_slilen(cb) {
checkLogin() const checkRes = await checkLoginTime()
.then(checkRes => { if(checkRes.status) {
console.log(checkRes) const res = await slelentLogin('13143340532', checkRes.res.time)
if(checkRes.status) { store.state.user.userInfo = res.userInfo
slelentLogin('13143340532', checkRes.res.time) return true
.then(res => { } else {
store.state.user.userInfo = res.userInfo return false
}) }
}
export async function login_wx() {
return new Promise(()=> {
uni.login({
success: async res => {
const loginRes = await wxLogin(res.code)
console.log(store)
if(loginRes.status) {
store.state.user.openid = loginRes.res.openid
store.state.user.unionid = loginRes.res.unionid
store.state.user.session_key = loginRes.res.session_key
}
} }
}) })
})
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment