Commit 5815bb4a by lirandong

添加 模板数据

parent 48af92d1
...@@ -4,6 +4,7 @@ import { concatParam } from '../constants/utils' ...@@ -4,6 +4,7 @@ import { concatParam } from '../constants/utils'
// import $config, { message, requestCode, tokens } from '@/config' // import $config, { message, requestCode, tokens } from '@/config'
import axios, { CancelTokenStatic, AxiosInstance } from 'axios' import axios, { CancelTokenStatic, AxiosInstance } from 'axios'
import { BASE_URL, FETCH_TIME_OUT, INTERFACE_REPEAT } from '../constants/counter' import { BASE_URL, FETCH_TIME_OUT, INTERFACE_REPEAT } from '../constants/counter'
import token from '../constants/token'
const concatParamMethod = new Set(['post', 'put']) const concatParamMethod = new Set(['post', 'put'])
// let refreshTokenState = false // 刷新 token的状态 // let refreshTokenState = false // 刷新 token的状态
...@@ -22,7 +23,7 @@ $axios.interceptors.request.use((config: any) => { ...@@ -22,7 +23,7 @@ $axios.interceptors.request.use((config: any) => {
// 设置token // 设置token
if (!noToken) { if (!noToken) {
// 默认添加token // 默认添加token
// config.headers.token = tokens.getToken() config.headers.visualToken = token.getToken()
} else { } else {
delete config.headers.noToken delete config.headers.noToken
} }
...@@ -58,24 +59,27 @@ $axios.interceptors.response.use( ...@@ -58,24 +59,27 @@ $axios.interceptors.response.use(
FetchSet.delete(config.config.FetchKey) FetchSet.delete(config.config.FetchKey)
// token过期处理 // token过期处理
const { data } = config const { data } = config
if (!data || !data.code) return Promise.reject(config) // if (!data || !data.code) return Promise.reject(config)
const { code } = data const { code } = data
if (code === '0') { // console.log({ config })
// 正确请求 console.log(!!code && code !== 0)
console.log({ config }) if (!!code && code !== 0) return Promise.reject(config.data)
return data return data
// } else if (code === requestCode.TOKNE_EXPIRED) { // if (code === '0') {
// // token失效重新请求 // // 正确请求
// try { // return data
// await refreshToken() // // } else if (code === requestCode.TOKNE_EXPIRED) {
// return $axios.request(config) // token刷新成功重新发起请求 // // // token失效重新请求
// } catch (error) { // // try {
// return Promise.reject(config) // // await refreshToken()
// } // // return $axios.request(config) // token刷新成功重新发起请求
} else { // // } catch (error) {
// 请求出现错误 // // return Promise.reject(config)
return Promise.reject(config.data) // // }
} // } else {
// // 请求出现错误
// return Promise.reject(config.data)
// }
}, },
async (error: any) => { async (error: any) => {
const { config } = error const { config } = error
......
import { ApiClient } from './client'
class UsersApi extends ApiClient {
/** 过去模板列表数据 */
getTempList(page: number) {
return this.request({ method: 'POST', url: `/template/get/list`, data: { p: page, c: 10 } })
}
}
export default new UsersApi()
import user from './users' import user from './users'
import common from './common'
export default { export default {
user user,
common
} }
...@@ -43,6 +43,28 @@ class App extends Component { ...@@ -43,6 +43,28 @@ class App extends Component {
navigationBarTitleText: 'Taro Demo', navigationBarTitleText: 'Taro Demo',
navigationBarBackgroundColor: '#fff' navigationBarBackgroundColor: '#fff'
}, },
// tabBar: {
// list: [
// {
// pagePath: 'pages/home/tempaltes/index',
// text: '模板市场',
// iconPath: './constants/images/market.png',
// selectedIconPath: './constants/images/market_ac.png'
// },
// {
// pagePath: 'pages/home/device/index',
// text: '设备与视片',
// iconPath: './constants/images/device.png',
// selectedIconPath: './constants/images/device_ac.png'
// },
// {
// pagePath: 'pages/home/user/index',
// text: '个人中心',
// iconPath: './constants/images/personal.png',
// selectedIconPath: './constants/images/personal_ac.png'
// }
// ]
// }
tabBar: tabBar:
process.env.TARO_ENV !== 'rn' process.env.TARO_ENV !== 'rn'
? { ? {
......
import { MyStorage } from './utils' import { MyStorage } from './utils'
class Token { class Token {
private initDone = false private initDone = false
private token = '0265dc09f4d24cf49fa360269cd8edbc-APP' private token = '676191a8b17442cfb06d31fdc936db6e-APP'
// constructor() { // constructor() {
// this.getStorageToken() // this.getStorageToken()
// } // }
...@@ -33,7 +33,7 @@ class Token { ...@@ -33,7 +33,7 @@ class Token {
try { try {
const { data } = await MyStorage.getItem({ key: 'token' }) const { data } = await MyStorage.getItem({ key: 'token' })
console.log({ data }) console.log({ data })
if (!!data) this.token = data // if (!!data) this.token = data
} catch (error) { } catch (error) {
console.warn('获取本地 token 失败~', error) console.warn('获取本地 token 失败~', error)
} }
......
...@@ -30,15 +30,21 @@ const RootStack = TaroRouter.initRouter( ...@@ -30,15 +30,21 @@ const RootStack = TaroRouter.initRouter(
list: [ list: [
{ {
pagePath: 'pages/home/tempaltes/index', pagePath: 'pages/home/tempaltes/index',
text: '模板市场' text: '模板市场',
iconPath: '../../constants/images/market.png',
selectedIconPath: '../../constants/images/market_ac.png'
}, },
{ {
pagePath: 'pages/home/device/index', pagePath: 'pages/home/device/index',
text: '设备与视片' text: '设备与视片',
iconPath: '../../constants/images/device.png',
selectedIconPath: '../../constants/images/device_ac.png'
}, },
{ {
pagePath: 'pages/home/user/index', pagePath: 'pages/home/user/index',
text: '个人中心' text: '个人中心',
iconPath: '../../constants/images/personal.png',
selectedIconPath: '../../constants/images/personal_ac.png'
} }
] ]
} }
......
.tempaltes {
width: 100%;
height: 100%;
flex-direction: column;
}
.search-bar {
height: 50;
padding-top: 10;
padding-bottom: 10;
padding-left: 12;
padding-right: 12;
background-color: white;
}
.search {
height: 100%;
padding: 0;
padding-left: 10;
color: #969799;
background-color: #f7f8fa;
}
.list-wrapper {
flex: 1;
}
import { ComponentClass } from 'react' import { ComponentClass } from 'react'
import Taro, { Component, Config } from '@tarojs/taro' import Taro, { Component, Config } from '@tarojs/taro'
import { View, Text } from '@tarojs/components' import { View, Text, Input, ScrollView } from '@tarojs/components'
// import './Tempaltes.less' import './index.less'
import api from '../../../api'
type PageStateProps = {} type PageStateProps = {}
...@@ -31,10 +32,29 @@ class Tempaltes extends Component { ...@@ -31,10 +32,29 @@ class Tempaltes extends Component {
} }
} }
async componentDidMount() {
console.log('componentDidMount')
try {
const res = await api.common.getTempList(1)
console.log({ res })
} catch (error) {
console.log({ error })
}
}
render() { render() {
console.log('componentDidMount')
return ( return (
<View className="Tempaltes"> <View className="tempaltes">
<Text>hello Tempaltes</Text> <View className="search-bar">
<Input className="search" placeholder="请输入搜索关键词" />
</View>
<ScrollView>
<Text>111111111111111</Text>
</ScrollView>
{/* <View className="list-wrapper">
<Text>111111111111111</Text>
</View> */}
</View> </View>
) )
} }
......
import { ComponentClass } from 'react'
import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import './index.less'
type PageStateProps = {}
type PageDispatchProps = {}
type PageOwnProps = {}
type PageState = {
name: string
}
type IProps = PageStateProps & PageDispatchProps & PageOwnProps
interface Item {
props: IProps
state: PageState
}
class Item extends Component {
constructor(props) {
super(props)
this.state = {
name: '小红'
}
}
render() {
return (
<View className="item">
<Text>hello world</Text>
</View>
)
}
}
export default Item as ComponentClass<PageOwnProps, PageState>
...@@ -12,7 +12,7 @@ class Index extends Component { ...@@ -12,7 +12,7 @@ class Index extends Component {
render() { render() {
const isLogin = token.isLogon() const isLogin = token.isLogon()
console.log({ isLogin }) // console.log({ isLogin })
return <View style={{ height: '100%', width: '100%' }}>{isLogin ? <Home /> : <Login />}</View> return <View style={{ height: '100%', width: '100%' }}>{isLogin ? <Home /> : <Login />}</View>
} }
} }
......
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 sign in to comment