Commit 940b1464 by lirandong

修改 异步获取数据方法

parent 63e1dcf2
import api from '@/api/index'
import { setTempList, setDeviceList, setFilmData } from './counter'
/** 获取 模板市场 数据列表 */
export function getTempList(page: number) {
return async dsipatch => {
try {
const { list, count } = await api.common.getTempList(page)
dsipatch(setTempList(list, count))
} catch (error) {
console.error(error)
}
}
}
/** 获取我的视片列表 */
export function getDeviceList(page: number) {
return async dispatch => {
try {
const { list, count } = await api.common.getMyFilmsList(page)
dispatch(setDeviceList(list, count))
} catch (error) {
console.error(error)
}
}
}
/** 获取我的设备数据 */
export function getFilmList(page: number) {
return async dispatch => {
try {
const { list, count } = await api.common.getMyDeviceList(page)
dispatch(setFilmData(list, count))
} catch (error) {
console.error(error)
}
}
}
import { ADD, MINUS, ADD_TEMP_LIST, ADD_DEVICE_LIST, ADD_FILM_LIST } from '../constants/counter' import { ADD_TEMP_LIST, ADD_DEVICE_LIST, ADD_FILM_LIST } from '../constants/counter'
export const add = () => {
return {
type: ADD
}
}
export const minus = () => {
return {
type: MINUS
}
}
// 异步的action
export function asyncAdd() {
return dispatch => {
setTimeout(() => {
dispatch(add())
}, 2000)
}
}
/** 修改模板市场数据 */ /** 修改模板市场数据 */
export function changeTempList(list: any[], count: number) { export function setTempList(list: any[], count: number) {
return { return {
list, list,
count, count,
...@@ -30,7 +10,7 @@ export function changeTempList(list: any[], count: number) { ...@@ -30,7 +10,7 @@ export function changeTempList(list: any[], count: number) {
} }
/** 修改我的视片数据 */ /** 修改我的视片数据 */
export function changeDeviceList(list: any[], count: number) { export function setDeviceList(list: any[], count: number) {
return { return {
list, list,
count, count,
...@@ -39,7 +19,7 @@ export function changeDeviceList(list: any[], count: number) { ...@@ -39,7 +19,7 @@ export function changeDeviceList(list: any[], count: number) {
} }
/** 修改我的设备数据 */ /** 修改我的设备数据 */
export function changeFilmData(list: any[], count: number) { export function setFilmData(list: any[], count: number) {
return { return {
list, list,
count, count,
......
export const ADD = 'ADD'
export const MINUS = 'MINUS'
export const ADD_TEMP_LIST = 'ADD_TEMP_LIST' export const ADD_TEMP_LIST = 'ADD_TEMP_LIST'
export const ADD_FILM_LIST = 'ADD_FILM_LIST' export const ADD_FILM_LIST = 'ADD_FILM_LIST'
export const ADD_DEVICE_LIST = 'ADD_DEVICE_LIST' export const ADD_DEVICE_LIST = 'ADD_DEVICE_LIST'
import api from '@/api/index' import api from '@/api/index'
import { ComponentClass } from 'react' import { ComponentClass } from 'react'
import { connect } from '@tarojs/redux' import { connect } from '@tarojs/redux'
import { showMyToast } from '@/common/utils'
import DeviceItem from '@/conpoments/device_item' import DeviceItem from '@/conpoments/device_item'
import { getFilmList } from '@/actions/asyncCounter'
import Taro, { Component, Config } from '@tarojs/taro' import Taro, { Component, Config } from '@tarojs/taro'
import { View, Text, ScrollView, Button, Checkbox } from '@tarojs/components' import { View, Text, ScrollView, Button, Checkbox } from '@tarojs/components'
import './index.scss' import './index.scss'
import { showMyToast } from '@/common/utils'
import { changeFilmData } from '@/actions/counter'
type PageStateProps = { type PageStateProps = {
list: any[] list: any[]
...@@ -14,7 +14,7 @@ type PageStateProps = { ...@@ -14,7 +14,7 @@ type PageStateProps = {
} }
type PageDispatchProps = { type PageDispatchProps = {
changeFilmData: (list: any[], conut: number) => void getFilmListData: (page: number) => void
} }
type PageOwnProps = {} type PageOwnProps = {}
...@@ -38,8 +38,8 @@ interface DeviceSelect { ...@@ -38,8 +38,8 @@ interface DeviceSelect {
return { list, count } return { list, count }
}, },
dispatch => ({ dispatch => ({
changeFilmData(list: any[], count: number) { getFilmListData(page: number) {
dispatch(changeFilmData(list, count)) dispatch(getFilmList(page))
} }
}) })
) )
...@@ -60,14 +60,13 @@ class DeviceSelect extends Component { ...@@ -60,14 +60,13 @@ class DeviceSelect extends Component {
this.changeAllCheck = this.changeAllCheck.bind(this) this.changeAllCheck = this.changeAllCheck.bind(this)
} }
async componentWillMount() { componentWillMount() {
const { page } = this.state this.getData()
try {
const { list, count } = await api.common.getMyDeviceList(page)
this.props.changeFilmData(list, count)
} catch (error) {
console.error(error)
} }
getData() {
const { page } = this.state
this.props.getFilmListData(page)
} }
changeItem({ equipmentId }) { changeItem({ equipmentId }) {
......
import api from '@/api/index' import api from '@/api/index'
import { ComponentClass } from 'react' import { ComponentClass } from 'react'
import { AtSwipeAction } from 'taro-ui' import { AtSwipeAction } from 'taro-ui'
import { showMyToast } from '@/common/utils'
import Taro, { Component } from '@tarojs/taro' import Taro, { Component } from '@tarojs/taro'
import DeviceItem from '@/conpoments/device_item' import DeviceItem from '@/conpoments/device_item'
import { showMyToast } from '@/common/utils' import { getFilmList } from '@/actions/asyncCounter'
import { View, Text, ScrollView } from '@tarojs/components' import { View, Text, ScrollView } from '@tarojs/components'
import './index.scss' import './index.scss'
import { connect } from '@tarojs/redux' import { connect } from '@tarojs/redux'
import { changeFilmData } from '@/actions/counter'
export interface IDeviceItem { export interface IDeviceItem {
filmId: any filmId: any
...@@ -32,7 +32,7 @@ type PageStateProps = { ...@@ -32,7 +32,7 @@ type PageStateProps = {
} }
type PageDispatchProps = { type PageDispatchProps = {
changeFilmData: (list: any[], count: number) => void getFilmListData: (page: number) => void
} }
type PageOwnProps = {} type PageOwnProps = {}
...@@ -58,8 +58,8 @@ interface MyDevice { ...@@ -58,8 +58,8 @@ interface MyDevice {
return { list, count } return { list, count }
}, },
dispacth => ({ dispacth => ({
changeFilmData(list: any[], count: number) { getFilmListData(page: number) {
dispacth(changeFilmData(list, count)) dispacth(getFilmList(page))
} }
}) })
) )
...@@ -84,13 +84,8 @@ class MyDevice extends Component { ...@@ -84,13 +84,8 @@ class MyDevice extends Component {
async getDate() { async getDate() {
const { page } = this.state const { page } = this.state
try {
const { list, count } = await api.common.getMyDeviceList(page)
this.cancelModal() this.cancelModal()
this.props.changeFilmData(list, count) this.props.getFilmListData(page)
} catch (error) {
console.error(error)
}
} }
selectAddDevice() { selectAddDevice() {
......
...@@ -4,8 +4,8 @@ import { AtSwipeAction } from 'taro-ui' ...@@ -4,8 +4,8 @@ import { AtSwipeAction } from 'taro-ui'
import { connect } from '@tarojs/redux' import { connect } from '@tarojs/redux'
import { showMyToast } from '@/common/utils' import { showMyToast } from '@/common/utils'
import Taro, { Component } from '@tarojs/taro' import Taro, { Component } from '@tarojs/taro'
import { changeDeviceList } from '@/actions/counter'
import { View, ScrollView } from '@tarojs/components' import { View, ScrollView } from '@tarojs/components'
import { getDeviceList } from '@/actions/asyncCounter'
import FilmListItem from '@/conpoments/film_list_item' import FilmListItem from '@/conpoments/film_list_item'
import './index.scss' import './index.scss'
...@@ -16,7 +16,7 @@ type PageStateProps = { ...@@ -16,7 +16,7 @@ type PageStateProps = {
} }
type PageDispatchProps = { type PageDispatchProps = {
changeDeviceList: (list: any, count: number) => void getDeviceListData: (page: number) => void
} }
type PageOwnProps = {} type PageOwnProps = {}
...@@ -45,13 +45,13 @@ interface Films { ...@@ -45,13 +45,13 @@ interface Films {
return { list, count } return { list, count }
}, },
dispacth => ({ dispacth => ({
changeDeviceList(list: any, count: number) { getDeviceListData(page: number) {
dispacth(changeDeviceList(list, count)) dispacth(getDeviceList(page))
} }
}) })
) )
class Films extends Component { class Films extends Component {
constructor(props) { constructor(props: any) {
super(props) super(props)
this.state = { page: 1 } this.state = { page: 1 }
} }
...@@ -61,13 +61,8 @@ class Films extends Component { ...@@ -61,13 +61,8 @@ class Films extends Component {
} }
async getData() { async getData() {
try {
const { page } = this.state const { page } = this.state
const { count, list } = await api.common.getMyFilmsList(page) this.props.getDeviceListData(page)
this.props.changeDeviceList(list, count)
} catch (error) {
console.error(error)
}
} }
async handleItem({ filmId }: IMilmListItme) { async handleItem({ filmId }: IMilmListItme) {
......
import api from '@/api/index'
import token from '@/common/token'
import { ComponentClass } from 'react' import { ComponentClass } from 'react'
import { connect } from '@tarojs/redux' import { connect } from '@tarojs/redux'
import { changeTempList } from '@/actions/counter' import { getTempList } from '@/actions/asyncCounter'
import Taro, { Component, Config } from '@tarojs/taro' import Taro, { Component, Config } from '@tarojs/taro'
import TempItem from './conpoments/temp_item/temp_item' import TempItem from './conpoments/temp_item/temp_item'
import { View, Input, ScrollView } from '@tarojs/components' import { View, Input, ScrollView } from '@tarojs/components'
...@@ -15,7 +13,7 @@ type PageStateProps = { ...@@ -15,7 +13,7 @@ type PageStateProps = {
} }
type PageDispatchProps = { type PageDispatchProps = {
changeTempList: (list: any[], count: number) => void getTempListData: (page: number) => void
} }
type PageOwnProps = {} type PageOwnProps = {}
...@@ -37,15 +35,14 @@ interface Tempaltes { ...@@ -37,15 +35,14 @@ interface Tempaltes {
return { list, count } return { list, count }
}, },
dispatch => ({ dispatch => ({
changeTempList(list, count) { getTempListData(page: number) {
dispatch(changeTempList(list, count)) dispatch(getTempList(page))
} }
}) })
) )
class Tempaltes extends Component { class Tempaltes extends Component {
config: Config = { config: Config = {
navigationBarTitleText: '', navigationBarTitleText: '',
// navigationStyle: 'custom'
navigationStyle: process.env.TARO_ENV === 'rn' ? 'custom' : 'default' navigationStyle: process.env.TARO_ENV === 'rn' ? 'custom' : 'default'
} }
constructor(props) { constructor(props) {
...@@ -56,21 +53,12 @@ class Tempaltes extends Component { ...@@ -56,21 +53,12 @@ class Tempaltes extends Component {
} }
async componentWillMount() { async componentWillMount() {
try { this.getData()
// console.log('componentWillMount', )
// Taro.getStorage({ key: 'tokne' })
// .then(res => {
// console.log({ res })
// })
// .catch(error => {
// console.log({ error })
// })
// console.log('token.getToken()', token.getToken())
const { list, count } = await api.common.getTempList(this.state.page)
this.props.changeTempList(list, count)
} catch (error) {
console.log({ error })
} }
getData() {
const { page } = this.state
this.props.getTempListData(page)
} }
shouldComponentUpdate(nextProps: IProps) { shouldComponentUpdate(nextProps: IProps) {
......
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