登录封装

This commit is contained in:
2022-05-09 10:03:23 +08:00
parent 16ba165fec
commit 5bae62d34d
15 changed files with 2400 additions and 30 deletions
+9 -3
View File
@@ -1,8 +1,11 @@
import { Component } from 'react'
import ContextBlueTooth from "@/use/contextBlueTooth"
import { Provider } from 'react-redux'
import configStore from './store'
import './app.scss'
const store = configStore()
class App extends Component {
componentDidMount () {}
@@ -16,9 +19,12 @@ class App extends Component {
// this.props.children 是将要会渲染的页面
render () {
return (
<ContextBlueTooth>
{this.props.children}
</ContextBlueTooth>
<ContextBlueTooth>
<Provider store={store}>
{this.props.children}
</Provider>
</ContextBlueTooth>
)
}
}
+4 -1
View File
@@ -24,4 +24,7 @@ export const IMG_CND_Prefix = "http://test.cdn.zzfzyc.com/"
// 上传图片视频
export const CDN_UPLOAD_IMG = `${UPLOAD_CDN_URL || ''}`;
export const CDN_UPLOAD_IMG = `${UPLOAD_CDN_URL || ''}`;
//appid
export const WX_APPID = 'wx6c8b9156543480b0'
+1 -1
View File
@@ -93,7 +93,7 @@ export default ({show = false, onClose}: param) => {
})
}
return (
<View className={styles.shop_cart_main}>
+2
View File
@@ -0,0 +1,2 @@
export const GETUSER = 'GETUSER'
export const SETUSER = 'SETUSER'
+8 -1
View File
@@ -62,9 +62,16 @@
.con{
display: grid;
grid-template-columns: 260px auto;
grid-template-rows: 50px 50px;
font-size: $font_size_medium;
color: $color_font_three;
.des_text{
display: flex;
margin-bottom: 16px;
text{
flex:1;
@include common_ellipsis(1);
}
}
}
}
.product_color{
+9 -5
View File
@@ -1,5 +1,5 @@
import { Button, Image, RichText, Swiper, SwiperItem, View } from '@tarojs/components'
import { Button, Image, RichText, Swiper, SwiperItem, Text, View } from '@tarojs/components'
import Taro, { useDidShow, useRouter, useShareAppMessage } from '@tarojs/taro';
import classnames from "classnames";
import DesSwiper from './components/swiper';
@@ -103,6 +103,10 @@ export default (props:params) => {
}
})
useDidShow(() => {
Taro.getCurrentPages()
})
return (
<View className={styles.main}>
@@ -127,10 +131,10 @@ export default (props:params) => {
<View className={styles.des_data}>
<View className={styles.title}>详情参数</View>
<View className={styles.con}>
<View>编号:0770</View>
<View>幅宽:160cm</View>
<View>克重:160g</View>
<View>成分:67.6%棉24%涤纶6.4%氨纶%氨纶</View>
<View className={styles.des_text}>编号:<Text>0770</Text></View>
<View className={styles.des_text}>幅宽:<Text>160cm</Text></View>
<View className={styles.des_text}>克重:<Text>160g</Text></View>
<View className={styles.des_text}>成分:<Text>67.6%棉24%涤纶6.4%氨纶%氨纶氨纶%氨纶</Text></View>
</View>
</View>
<View className={styles.product_color}>
+22 -2
View File
@@ -46,12 +46,32 @@ export default () => {
console.log('12123')
}, 1000)
}
const goto = function (e) {
var t = this
Taro.navigateTo({
url: '/pages/details/index',
events: {
// 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
backFromTargetPage: function (backData) {
console.log('好啦,可以在这里写你的逻辑了', backData)
if (backData.from == 'page2') {
// 监听到 page2 返回
console.log('好啦,可以在这里写你的逻辑了', backData)
t.setData({
isBackFromPage2: !0
})
}
}
}
})
}
return (
<MoveBtn onClick={() => setShowShopCart(!showShopCart)}>
<View className={styles.main}>
<View onClick={(e) => goto(e)}>aaa</View>
<Swiper/>
<View className={styles.search}>
<View className={styles.search_collect}>我的收藏</View>
+6
View File
@@ -0,0 +1,6 @@
import { combineReducers } from 'redux'
import userInfo from './userInfo'
export default combineReducers({
userInfo
})
+24
View File
@@ -0,0 +1,24 @@
import { GETUSER, SETUSER } from '../constants/userInfo'
const INIT_USER = {
name: '张三',
phone: '110',
avatarUrl: '',
token: '',
}
export default function counter (state = INIT_USER, action) {
switch (action.type) {
case GETUSER:
return {
...state,
}
case SETUSER:
return {
...state,
}
default:
return state
}
}
+27
View File
@@ -0,0 +1,27 @@
import { createStore, applyMiddleware, compose } from 'redux'
import thunkMiddleware from 'redux-thunk'
import rootReducer from '@/reducers'
const composeEnhancers =
typeof window === 'object' &&
(window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
(window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
// Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize...
}) : compose
const middlewares = [
thunkMiddleware
]
if (process.env.NODE_ENV === 'development' && process.env.TARO_ENV !== 'quickapp') {
middlewares.push(require('redux-logger').createLogger())
}
const enhancer = composeEnhancers(
applyMiddleware(...middlewares),
)
export default function configStore () {
const store = createStore(rootReducer, enhancer)
return store
}
+3 -1
View File
@@ -19,13 +19,15 @@ $font_size_min: 22px;
//省略号
@mixin common_ellipsis($params:1) {
overflow: hidden;
display: -webkit-box;
white-space:normal;
text-overflow:ellipsis;
word-break:break-all;
-webkit-box-orient: vertical;
-webkit-line-clamp: $params;
text-overflow:ellipsis;
}
+85
View File
@@ -0,0 +1,85 @@
import { useEffect, useState } from "react"
import { WX_APPID } from "@/common/constant"
export default () => {
const [loginState, setLoginState] = useState({
session_key: '',
token: '',
userInfo: ''
})
useEffect(() => {
getToken()
}, [])
const getToken = () => {
Taro.login({
success: function (res) {
if (res.code) {
console.log('number::', res.code)
Taro.request({
url: 'https://dev.zzfzyc.com/lymarket/v1/mall/login',
method: 'POST',
data: {
js_code: res.code,
},
header: {
platform: 6,
Appid: WX_APPID
},
success: (e) => {
let {data} = e.data
setLoginState({
...loginState,
session_key: data.session_key,
token: data.token
})
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
},
fail: function(e) {
console.log('e::',e)
}
})
}
const getUserInfo = () => {
Taro.getUserProfile({
desc: '用于完善会员资料',
success: (res) => {
Taro.request({
url: 'https://dev.zzfzyc.com/lymarket/v1/mall/user/decrypt',
method: 'POST',
data: {
session_key: loginState.session_key,
raw_data: res.rawData,
signature: res.signature,
encrypted_data: res.encryptedData,
iv: res.iv
},
header: {
platform: 6,
Authorization: loginState.token,
Appid: WX_APPID
},
success: (e) => {
console.log('123123')
},
fail: (e) => {
console.log(e)
}
})
}
})
}
return {
getToken,
getUserInfo
}
}