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