Commit 287433d6 by 王树冬

更新api状态

parent 5703c2fb
...@@ -3,3 +3,4 @@ dist/ ...@@ -3,3 +3,4 @@ dist/
.rn_temp/ .rn_temp/
node_modules/ node_modules/
img/ img/
package-lock.json
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
"description": "taro kit", "description": "taro kit",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"start": "npm run build:weapp -- --watch",
"build:weapp": "taro build --type weapp", "build:weapp": "taro build --type weapp",
"build:h5": "taro build --type h5", "build:h5": "taro build --type h5",
"build:rn": "taro build --type rn", "build:rn": "taro build --type rn",
...@@ -16,37 +17,38 @@ ...@@ -16,37 +17,38 @@
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@tarojs/async-await": "^1.0.0-beta.29", "@tarojs/async-await": "^1.0.3",
"@tarojs/components": "^1.0.0-beta.29", "@tarojs/components": "^1.0.0-beta.29",
"@tarojs/redux": "^1.0.0-beta.29", "@tarojs/redux": "^1.0.3",
"@tarojs/redux-h5": "^1.0.0-beta.29", "@tarojs/redux-h5": "^1.0.0-beta.29",
"@tarojs/router": "^1.0.0-beta.29", "@tarojs/router": "^1.0.0-beta.29",
"@tarojs/taro": "^1.0.0-beta.29", "@tarojs/taro": "^1.0.0-beta.29",
"@tarojs/taro-h5": "^1.0.0-beta.29", "@tarojs/taro-h5": "^1.0.0-beta.29",
"@tarojs/taro-weapp": "^1.0.0-beta.29", "@tarojs/taro-weapp": "^1.0.3",
"config": "^2.0.1",
"nervjs": "^1.3.0", "nervjs": "^1.3.0",
"redux": "^4.0.0", "redux": "^4.0.0",
"redux-logger": "^3.0.6", "redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0" "redux-thunk": "^2.3.0"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^16.4.8", "@tarojs/plugin-babel": "^1.0.3",
"@types/webpack-env": "^1.13.6",
"@tarojs/plugin-babel": "^1.0.0-beta.29",
"@tarojs/plugin-csso": "^1.0.0-beta.29", "@tarojs/plugin-csso": "^1.0.0-beta.29",
"@tarojs/plugin-stylus": "^1.0.0-beta.29", "@tarojs/plugin-stylus": "^1.0.0-beta.29",
"@tarojs/plugin-uglifyjs": "^1.0.0-beta.29", "@tarojs/plugin-uglifyjs": "^1.0.0-beta.29",
"@tarojs/webpack-runner": "^1.0.0-beta.29", "@tarojs/webpack-runner": "^1.0.0-beta.29",
"@types/react": "^16.4.8",
"@types/webpack-env": "^1.13.6",
"babel-eslint": "^8.2.3",
"babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-jsx-stylesheet": "^0.6.5", "babel-plugin-transform-jsx-stylesheet": "^0.6.5",
"babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1", "babel-preset-env": "^1.6.1",
"babel-eslint": "^8.2.3",
"eslint": "^4.19.1", "eslint": "^4.19.1",
"eslint-config-taro": "^1.0.0-beta.29", "eslint-config-taro": "^1.0.0-beta.29",
"eslint-plugin-react": "^7.8.2",
"eslint-plugin-import": "^2.12.0", "eslint-plugin-import": "^2.12.0",
"eslint-plugin-react": "^7.8.2",
"eslint-plugin-taro": "^1.0.0-beta.29" "eslint-plugin-taro": "^1.0.0-beta.29"
} }
} }
{ {
"miniprogramRoot": "./dist", "miniprogramRoot": "./dist",
"projectname": "taro%20news", "projectname": "taro-kit",
"description": "demo", "description": "demo",
"appid": "wx8566afef50e5f76b", "appid": "wx8566afef50e5f76b",
"setting": { "setting": {
"urlCheck": true, "urlCheck": false,
"es6": false, "es6": false,
"postcss": false, "postcss": false,
"minified": false, "minified": false,
......
> 项目会不断迭代,有需求欢迎issue > 项目会不断迭代,有需求欢迎issue
> 如果能帮到你,那就给个star呗!
## 功能列表 ## 功能列表
* [x] 封装api请求方式 * [x] 封装api请求方式
* [x] 更方便的创建action:增加createApiAction * [x] 更方便的创建action:增加createApiAction
* [x] 基础像素试着为1倍即:1px 会编译成 2rpx(小程序默认是2倍)符合习惯 * [x] 基础像素试着为1倍即:1px 会编译成 2rpx(小程序默认是2倍)符合习惯
* [x] 基础demo案列 * [x] 基础demo案列
## 用法
```
npm i
npm start
```
## 更方面的创建action ## 更方面的创建action
> 未封装前 > 未封装前
``` ```
...@@ -36,9 +42,9 @@ export function list() { ...@@ -36,9 +42,9 @@ export function list() {
} }
} }
``` ```
![2018-09-25-15-50-45](http://file.shudong.wang/2018-09-25-15-50-45.png) ![2018-09-25-15-50-45](http://img.shudong.wang/2018-09-25-15-50-45.png)
> 封装后请求api的使用方式 > 封装后请求api的使用方式
``` ```
export const list = createApiAction(LIST, params => api.get('news/list', params)) export const list = createApiAction(LIST, params => api.get('news/list', params))
``` ```
![2018-09-25-15-51-45](http://file.shudong.wang/2018-09-25-15-51-45.png) ![2018-09-25-15-51-45](http://img.shudong.wang/2018-09-25-15-51-45.png)
...@@ -82,7 +82,7 @@ export function asyncAdd() { ...@@ -82,7 +82,7 @@ export function asyncAdd() {
// export const list = createApiAction(LIST, params => api.get('news/list', params)) // export const list = createApiAction(LIST, params => api.get('news/list', params))
export const list = createApiAction(LIST, params => { export const list = createApiAction(LIST, params => {
console.log('list',params); console.log('list',params);
return api.get('news/list', params) return api.get('NervJS/taro/issues', params)
}) })
export default bindActionCreators({ export default bindActionCreators({
......
...@@ -10,17 +10,15 @@ export const HTTP_STATUS = { ...@@ -10,17 +10,15 @@ export const HTTP_STATUS = {
GATEWAY_TIMEOUT: 504 GATEWAY_TIMEOUT: 504
} }
export const COMMON_STATUS = { // export const COMMON_STATUS = {
NOT_FOUND: -40400, // "请求资源不存在", // NOT_FOUND: -40400, // "请求资源不存在",
API_NOT_FOUND: -40401, // "请求方法不存在", // API_NOT_FOUND: -40401, // "请求方法不存在",
EXCEPTION: -50000, // "系统异常", // EXCEPTION: -50000, // "系统异常",
PARAM_ERROR: -40001, // "参数错误", // PARAM_ERROR: -40001, // "参数错误",
AUTH_FAILED: -40100, // "认证错误", // AUTH_FAILED: -40100, // "认证错误",
NO_PERMISION: -40302, // "没有权限", // NO_PERMISION: -40302, // "没有权限",
NET_REQUEST_FAILED: -40000, // "网络请求失败", // NET_REQUEST_FAILED: -40000, // "网络请求失败",
ERROR_TENANT: -401100, // "不存在选择的公司,当租户id为空的时候", // }
ERROR_NO_TENANT: -401200 // "租户id错误的时候",
}
// promise status // promise status
export const SUCCESS = { success:'success'} export const SUCCESS = { success:'success'}
......
...@@ -43,17 +43,19 @@ class Index extends Component { ...@@ -43,17 +43,19 @@ class Index extends Component {
console.log('props', props); console.log('props', props);
// this.state = { date: new Date() } // this.state = { date: new Date() }
// let params = { // let params = {
// page: 2, perPage: 2 // page: 2, per_page: 2
// } // }
this.state = { this.state = {
page: 1, perPage: 10 page: 1, per_page: 10
} }
if (Object.keys(props).length === 0) return
props.getList(this.state) props.getList(this.state)
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps) console.log(this.props, nextProps)
} }
componentWillMount() { componentWillMount() {
console.log('thisprops', this.props);
this.props.getList(this.state) this.props.getList(this.state)
} }
componentWillUnmount() { componentWillUnmount() {
...@@ -76,9 +78,9 @@ class Index extends Component { ...@@ -76,9 +78,9 @@ class Index extends Component {
this.setState({ this.setState({
page: this.state.page + 1 page: this.state.page + 1
}) })
const { page, perPage } = this.state const { page, per_page } = this.state
let params = { let params = {
page: this.state.page + 1, perPage: perPage page: this.state.page + 1, per_page: per_page
} }
console.log(this.props, 'onReachBottom') console.log(this.props, 'onReachBottom')
this.props.getList(params) this.props.getList(params)
......
...@@ -19,7 +19,7 @@ export default function counter (state = INITIAL_STATE, action) { ...@@ -19,7 +19,7 @@ export default function counter (state = INITIAL_STATE, action) {
num: state.num - 1 num: state.num - 1
} }
case LIST: case LIST:
let data = state.list.concat(action.payload.data.news) let data = state.list.concat(action.payload.data)
// Object.assign(state.list, action.payload.data.news) // Object.assign(state.list, action.payload.data.news)
console.log('data',data) console.log('data',data)
console.log('state',state) console.log('state',state)
......
import Taro from '@tarojs/taro' import Taro from '@tarojs/taro'
import { HTTP_STATUS, COMMON_STATUS, RESULT_STATUS } from '../const/status.js' import { HTTP_STATUS } from '../const/status'
// import config from '../config/index.js' import { base } from './config'
import { logError } from '../utils' import { logError } from '../utils'
const baseURL = "https://shudong.wang/v1/"
// Taro.request({
// url: baseURL + '',
// data: {
// foo: 'foo',
// bar: 10
// },
// header: {
// 'content-type': 'application/json'
// }
// })
// .then(res => console.log(res.data))
const token = '' const token = ''
export default { export default {
baseOptions(params, method = 'GET') { baseOptions(params, method = 'GET') {
let { url, data } = params let { url, data } = params
...@@ -27,12 +16,20 @@ export default { ...@@ -27,12 +16,20 @@ export default {
const option = { const option = {
isShowLoading: false, isShowLoading: false,
loadingText: '正在加载', loadingText: '正在加载',
url: baseURL + url, url: base + url,
data: data, data: data,
method: method, method: method,
header: { 'content-type': contentType, 'token': token }, header: { 'content-type': contentType, 'token': token },
success(res) { success(res) {
return res if (res.statusCode === HTTP_STATUS.NOT_FOUND) {
return logError('api', '请求资源不存在')
} else if (res.statusCode === HTTP_STATUS.BAD_GATEWAY) {
return logError('api', '服务端出现了问题')
} else if (res.statusCode === HTTP_STATUS.FORBIDDEN) {
return logError('api', '没有权限访问')
} else if (res.statusCode === HTTP_STATUS.SUCCESS) {
return res.data
}
}, },
error(e) { error(e) {
logError('api', '请求接口出现问题', e) logError('api', '请求接口出现问题', e)
...@@ -42,7 +39,6 @@ export default { ...@@ -42,7 +39,6 @@ export default {
}, },
get(url, data = '') { get(url, data = '') {
let option = { url, data } let option = { url, data }
console.log('data', data)
return this.baseOptions(option) return this.baseOptions(option)
}, },
post: function (url, data, contentType) { post: function (url, data, contentType) {
......
export base = "http://api.shudong.wang/v1/" // https://api.github.com/repos/NervJS/taro/issues?per_page=1&page=2
// export base = "http://api.shudong.wang/v1/"
export const base = "https://api.github.com/repos/"
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