Commit c1292415 by hank

设备组功能开发

parent 3f344ec8
......@@ -231,46 +231,60 @@ class UsersApi extends ApiClient {
url: `/calendar/del/info/${id}`
})
}
/** 添加设备组 */
getGroupList(page: number = 1, limit: number = 1000000) {
/** 获取组列表 */
getGroupList(page: number = 1, limit: number = 100000000) {
return this.request({
method: 'post',
url: `/calendar/get/list?p=${page}&c=${limit}`,
data: {}
method: 'get',
url: `/myequipmentgroup/get/list?p=${page}&c=${limit}`
})
}
/** 添加设备组 */
addGroup(id) {
addGroup(equipmentGroupName: string) {
return this.request({
method: 'post',
url: `/calendar/del/info/${id}`
url: `/myequipmentgroup/add/info`,
data: {
equipmentGroupName
}
})
}
/** 编辑设备组 */
getGroupDevice(id) {
/** 获取组下设备 */
getGroupDevice(equipmentGroupId: string = '', equipmentGroupName: string = '') {
return this.request({
method: 'post',
url: `/calendar/del/info/${id}`
url: `/myequipment/get/filter/list`,
data: {
equipmentGroupId,
equipmentGroupName
}
})
}
editGroup(id) {
editGroup(equipmentGroupId: string, equipmentGroupName: string) {
return this.request({
method: 'post',
url: `/calendar/del/info/${id}`
url: `/myequipmentgroup/update/info`,
data: {
equipmentGroupId,
equipmentGroupName
}
})
}
/** 删除设备组 */
deleteGroup(id) {
return this.request({
method: 'post',
url: `/calendar/del/info/${id}`
method: 'GET',
url: `/myequipmentgroup/del/${id}`
})
}
/** 删除设备组,摸个设备 */
deleteGroupDevice(id) {
deleteGroupDevice(equipmentGroupId: string, equipmentId: string) {
return this.request({
method: 'post',
url: `/calendar/del/info/${id}`
url: `/myequipmentgroup/del/equipment`,
data: {
equipmentGroupId: equipmentGroupId,
equipmentId: equipmentId
}
})
}
}
......
import api from '@/api/index'
import { ComponentClass } from 'react'
import { AtSwipeAction } from 'taro-ui'
import { connect } from '@tarojs/redux'
import ListView from '@/conpoments/list_view'
import Taro, { Component, Config } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import DeviceItem from '@/conpoments/device_item'
import { getFilmList } from '@/actions/asyncCounter'
import { showMyToast } from '@/common/utils'
import './index.scss'
......@@ -36,10 +34,10 @@ type PageOwnProps = {
}
type PageState = {
deviceCode: string
showModal: boolean
deviceList: IDeviceItem[]
groupId: string | ''
list: any[]
}
type IProps = PageStateProps & PageDispatchProps & PageOwnProps
......@@ -49,17 +47,6 @@ interface DeviceGroup {
state: PageState
}
@connect(
({ counter }) => {
const { list, count } = counter.filmData
return { list, count }
},
dispacth => ({
getFilmListData(page: number) {
dispacth(getFilmList(page))
}
})
)
class DeviceGroup extends Component {
config: Config = {
navigationBarTitleText: '组详情'
......@@ -69,10 +56,10 @@ class DeviceGroup extends Component {
super(props)
const { id } = this.$router.params
this.state = {
deviceCode: '',
deviceList: [],
showModal: false,
groupId: id
groupId: id,
list: []
}
this.selectAddDevice = this.selectAddDevice.bind(this)
Taro.setNavigationBarTitle({
......@@ -89,7 +76,12 @@ class DeviceGroup extends Component {
this.getDate()
}
async getDate() {
this.props.getFilmListData(this.page)
api.common.getGroupDevice(this.$router.params.id).then(res => {
const list = res
this.setState({
list: list || []
})
})
}
selectAddDevice() {
......@@ -100,16 +92,17 @@ class DeviceGroup extends Component {
async handleItem(item: IDeviceItem, info) {
const { text } = info
const { equipmentId } = item
const { id } = this.$router.params
if (text === '删除') {
Taro.showModal({ content: '确定要删除?' }).then(async ({ confirm }) => {
if (confirm) {
try {
await api.common.deleteGroupDevice(equipmentId)
await api.common.deleteGroupDevice(id, equipmentId)
this.getDate()
showMyToast({ title: '删除成功~' })
} catch (error) {
console.error(error)
showMyToast({ result: error, title: '失败成功~' })
showMyToast({ result: error, title: '失败~' })
}
}
})
......@@ -134,7 +127,8 @@ class DeviceGroup extends Component {
Taro.navigateTo({ url: `/pages/home/device/device_detail/index?equipmentId=${equipmentId}` })
}
render() {
const { list, count, height } = this.props
const { count, height } = this.props
const { list } = this.state
return (
<View className="device-list">
<ListView
......
......@@ -13,7 +13,7 @@
flex: 1;
&-view {
height: 100%;
height: calc(100vh - 200px);
}
}
......
......@@ -25,6 +25,7 @@ type PageState = {
page: number
filmId: string
checked: Set<string>
searchValue: string | ''
}
type IProps = PageStateProps & PageDispatchProps & PageOwnProps
......@@ -56,10 +57,12 @@ class DeviceSelect extends Component {
this.state = {
filmId,
page: 1,
checked: new Set()
checked: new Set(),
searchValue: ''
}
this.updateBind = this.updateBind.bind(this)
this.changeAllCheck = this.changeAllCheck.bind(this)
this.searchChange = this.searchChange.bind(this)
}
componentWillMount() {
......@@ -120,7 +123,12 @@ class DeviceSelect extends Component {
}
}
searchChange() {}
searchChange(target) {
console.log(target)
this.setState({
searchValue: target
})
}
shouldComponentUpdate(nextProps: IProps, nextState: PageState) {
const { checked } = this.state
......@@ -132,11 +140,11 @@ class DeviceSelect extends Component {
render() {
const { list } = this.props
const { checked } = this.state
const { checked, searchValue } = this.state
const { size } = checked
return (
<View className="device-bind">
<AtSearchBar value={''} onChange={this.searchChange} />
<AtSearchBar showActionButton value={searchValue} onChange={this.searchChange} />
<View className="device-bind-scroll">
<ScrollView className="device-bind-scroll-view">
{list.map(item => (
......
import api from '@/api/index'
import { ComponentClass } from 'react'
import { AtSwipeAction } from 'taro-ui'
import { connect } from '@tarojs/redux'
import ListView from '@/conpoments/list_view'
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Input } from '@tarojs/components'
import Modal from '@/conpoments/modal'
import { getFilmList } from '@/actions/asyncCounter'
import { showMyToast } from '@/common/utils'
import Ble from '@/common/bluetooth'
import './index.scss'
import template from '@/api/template'
export interface IDeviceItem {
filmId: any
filmName: any
......@@ -29,19 +25,17 @@ type PageStateProps = {
count: number
}
type PageDispatchProps = {
getFilmListData: (page: number) => void
}
type PageDispatchProps = {}
type PageOwnProps = {
height: number
}
type PageState = {
deviceCode: string
showModal: boolean
temp: any
deviceList: IDeviceItem[]
list: any[]
}
type IProps = PageStateProps & PageDispatchProps & PageOwnProps
......@@ -51,27 +45,16 @@ interface DeviceGroup {
state: PageState
}
@connect(
({ counter }) => {
const { list, count } = counter.filmData
return { list, count }
},
dispacth => ({
getFilmListData(page: number) {
dispacth(getFilmList(page))
}
})
)
class DeviceGroup extends Component {
protected page = 1
constructor(props: any) {
super(props)
this.state = {
deviceCode: '',
deviceList: [],
list: [],
showModal: false,
temp: {
name: ''
equipmentGroupName: ''
}
}
this.cancelModal = this.cancelModal.bind(this)
......@@ -89,14 +72,20 @@ class DeviceGroup extends Component {
}
async getDate() {
this.cancelModal()
this.props.getFilmListData(this.page)
// this.props.getFilmListData(this.page)
api.common.getGroupList().then(res => {
const list = res.list
this.setState({
list: list
})
})
}
AddGroup() {
this.setState({
showModal: !this.state.showModal,
temp: {
name: ''
equipmentGroupName: ''
}
})
}
......@@ -112,18 +101,18 @@ class DeviceGroup extends Component {
async handleItem(item, info) {
const { text } = info
const { equipmentId } = item
const { equipmentGroupId } = item
if (text === '编辑') {
// console.log('')
this.setState({
showModal: true,
temp: Object.assign({ name: '测试组名' }, item)
temp: Object.assign({ equipmentGroupName: '测试组名' }, item)
})
} else if (text === '删除') {
Taro.showModal({ content: '确定要删除?' }).then(async ({ confirm }) => {
if (confirm) {
try {
await api.common.deleteGroup(equipmentId)
await api.common.deleteGroup(equipmentGroupId)
this.getDate()
showMyToast({ title: '删除成功~' })
} catch (error) {
......@@ -156,16 +145,18 @@ class DeviceGroup extends Component {
inputConfirm() {
console.log()
const { temp } = this.state
if (!temp.name) {
if (!temp.equipmentGroupName) {
showMyToast({ title: '请输入设备组名称' })
return
}
if (temp.equipmentId) {
if (temp.equipmentGroupId) {
console.log('更新')
api.common
.editGroup(temp.name)
.editGroup(temp.equipmentGroupId, temp.equipmentGroupName)
.then(() => {
showMyToast({ title: '更新成功' })
this.cancelModal()
this.getDate()
})
.catch(() => {
showMyToast({ title: '更新失败' })
......@@ -173,13 +164,15 @@ class DeviceGroup extends Component {
} else {
console.log('创建')
api.common
.addGroup(temp.name)
.addGroup(temp.equipmentGroupName)
.then(() => {
showMyToast({ title: '创建成功' })
this.getDate()
})
.catch(() => {
showMyToast({ title: '创建失败' })
})
this.cancelModal()
}
}
......@@ -187,15 +180,15 @@ class DeviceGroup extends Component {
let value = target.value
this.setState({
temp: Object.assign(this.state.temp, {
name: value
equipmentGroupName: value
})
})
}
render() {
const { list, count, height } = this.props
const { showModal, temp } = this.state
let name = temp && temp.name ? '设备组信息' : '新建设备组'
const { count, height } = this.props
const { showModal, temp, list } = this.state
let name = temp && temp.equipmentGroupName ? '设备组信息' : '新建设备组'
return (
<View className="device-list">
<ListView
......@@ -225,8 +218,10 @@ class DeviceGroup extends Component {
}
]}
>
<View className="group-item" onClick={() => this.goDetail(item.equipmentId)}>
<View className="group-item-content">{item.equipmentName}</View>
<View className="group-item" onClick={() => this.goDetail(item.equipmentGroupId)}>
<View className="group-item-content">
{item.equipmentGroupName}({item.equipmentCount})
</View>
</View>
</AtSwipeAction>
))}
......@@ -250,7 +245,7 @@ class DeviceGroup extends Component {
<Input
placeholder="请输入设备组名称"
className="film-modal-input"
value={temp.name}
value={temp.equipmentGroupName}
onInput={this.changeName}
/>
</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