Commit 5815bb4a by lirandong

添加 模板数据

parent 48af92d1
......@@ -4,6 +4,7 @@ import { concatParam } from '../constants/utils'
// import $config, { message, requestCode, tokens } from '@/config'
import axios, { CancelTokenStatic, AxiosInstance } from 'axios'
import { BASE_URL, FETCH_TIME_OUT, INTERFACE_REPEAT } from '../constants/counter'
import token from '../constants/token'
const concatParamMethod = new Set(['post', 'put'])
// let refreshTokenState = false // 刷新 token的状态
......@@ -22,7 +23,7 @@ $axios.interceptors.request.use((config: any) => {
// 设置token
if (!noToken) {
// 默认添加token
// config.headers.token = tokens.getToken()
config.headers.visualToken = token.getToken()
} else {
delete config.headers.noToken
}
......@@ -58,24 +59,27 @@ $axios.interceptors.response.use(
FetchSet.delete(config.config.FetchKey)
// token过期处理
const { data } = config
if (!data || !data.code) return Promise.reject(config)
// if (!data || !data.code) return Promise.reject(config)
const { code } = data
if (code === '0') {
// 正确请求
console.log({ config })
return data
// } else if (code === requestCode.TOKNE_EXPIRED) {
// // token失效重新请求
// try {
// await refreshToken()
// return $axios.request(config) // token刷新成功重新发起请求
// } catch (error) {
// return Promise.reject(config)
// }
} else {
// 请求出现错误
return Promise.reject(config.data)
}
// console.log({ config })
console.log(!!code && code !== 0)
if (!!code && code !== 0) return Promise.reject(config.data)
return data
// if (code === '0') {
// // 正确请求
// return data
// // } else if (code === requestCode.TOKNE_EXPIRED) {
// // // token失效重新请求
// // try {
// // await refreshToken()
// // return $axios.request(config) // token刷新成功重新发起请求
// // } catch (error) {
// // return Promise.reject(config)
// // }
// } else {
// // 请求出现错误
// return Promise.reject(config.data)
// }
},
async (error: any) => {
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 common from './common'
export default {
user
user,
common
}
......@@ -43,6 +43,28 @@ class App extends Component {
navigationBarTitleText: 'Taro Demo',
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:
process.env.TARO_ENV !== 'rn'
? {
......
import { MyStorage } from './utils'
class Token {
private initDone = false
private token = '0265dc09f4d24cf49fa360269cd8edbc-APP'
private token = '676191a8b17442cfb06d31fdc936db6e-APP'
// constructor() {
// this.getStorageToken()
// }
......@@ -33,7 +33,7 @@ class Token {
try {
const { data } = await MyStorage.getItem({ key: 'token' })
console.log({ data })
if (!!data) this.token = data
// if (!!data) this.token = data
} catch (error) {
console.warn('获取本地 token 失败~', error)
}
......
......@@ -30,15 +30,21 @@ const RootStack = TaroRouter.initRouter(
list: [
{
pagePath: 'pages/home/tempaltes/index',
text: '模板市场'
text: '模板市场',
iconPath: '../../constants/images/market.png',
selectedIconPath: '../../constants/images/market_ac.png'
},
{
pagePath: 'pages/home/device/index',
text: '设备与视片'
text: '设备与视片',
iconPath: '../../constants/images/device.png',
selectedIconPath: '../../constants/images/device_ac.png'
},
{
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 Taro, { Component, Config } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
// import './Tempaltes.less'
import { View, Text, Input, ScrollView } from '@tarojs/components'
import './index.less'
import api from '../../../api'
type PageStateProps = {}
......@@ -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() {
console.log('componentDidMount')
return (
<View className="Tempaltes">
<Text>hello Tempaltes</Text>
<View className="tempaltes">
<View className="search-bar">
<Input className="search" placeholder="请输入搜索关键词" />
</View>
<ScrollView>
<Text>111111111111111</Text>
</ScrollView>
{/* <View className="list-wrapper">
<Text>111111111111111</Text>
</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 {
render() {
const isLogin = token.isLogon()
console.log({ isLogin })
// console.log({ isLogin })
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