tangxilong
1 year ago
13 changed files with 345 additions and 28 deletions
@ -0,0 +1,90 @@ |
|||
'use strict' |
|||
|
|||
const request = require('superagent') |
|||
const moment = require('moment') |
|||
|
|||
|
|||
// function getFileCarImages (opts) {
|
|||
|
|||
// return async function (ctx, next) {
|
|||
// let error = { message: '文件夹名称更新失败' }
|
|||
// const models = ctx.fs.dc.models
|
|||
// const { page, limit, } = ctx.query
|
|||
// try {
|
|||
// let searchWhere = {}
|
|||
// let option = {
|
|||
// where: searchWhere,
|
|||
// order: [["id", "desc"]],
|
|||
// }
|
|||
|
|||
|
|||
// option.where = searchWhere
|
|||
|
|||
// let limit_ = limit || 10
|
|||
// let page_ = page || 1
|
|||
// let offset = (page_ - 1) * limit_
|
|||
// if (limit && page) {
|
|||
// option.limit = limit_
|
|||
// option.offset = offset
|
|||
// }
|
|||
|
|||
// const res = await models.CarImages.findAndCount(option)
|
|||
|
|||
// error = null
|
|||
// } catch (err) {
|
|||
// ctx.status = 500
|
|||
// ctx.body = { detail: err, ...error }
|
|||
// }
|
|||
|
|||
// if (error) {
|
|||
// ctx.status = 400
|
|||
// ctx.body = { ...error }
|
|||
// } else {
|
|||
// ctx.status = 200
|
|||
// ctx.body = { message: '文件夹名称更新成功' }
|
|||
// }
|
|||
// }
|
|||
// }
|
|||
|
|||
|
|||
|
|||
function getFileCarImages (opts) { |
|||
return async function (ctx, next) { |
|||
|
|||
const models = ctx.fs.dc.models |
|||
const { page, limit, } = ctx.query |
|||
const Op = ctx.fs.dc.ORM.Op |
|||
let errMsg = { message: '获取图片失败' } |
|||
try { |
|||
let searchWhere = {} |
|||
let option = { |
|||
where: searchWhere, |
|||
order: [["id", "ASC"]], |
|||
} |
|||
|
|||
|
|||
option.where = searchWhere |
|||
|
|||
let limit_ = limit || 10 |
|||
let page_ = page || 1 |
|||
let offset = (page_ - 1) * limit_ |
|||
if (limit && page) { |
|||
option.limit = limit_ |
|||
option.offset = offset |
|||
} |
|||
|
|||
const res = await models.CarImages.findAndCount(option) |
|||
ctx.status = 200 |
|||
ctx.body = res |
|||
} catch (error) { |
|||
|
|||
ctx.status = 400 |
|||
ctx.body = errMsg |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
module.exports = { |
|||
getFileCarImages |
|||
} |
@ -0,0 +1,44 @@ |
|||
/* eslint-disable*/ |
|||
|
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const CarImages = sequelize.define("carImages", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "car_images_id_uindex" |
|||
}, |
|||
url: { |
|||
type: DataTypes.STRING, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "图片路径", |
|||
primaryKey: false, |
|||
field: "url", |
|||
autoIncrement: false |
|||
}, |
|||
time: { |
|||
type: DataTypes.DATE, |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: "时间", |
|||
primaryKey: false, |
|||
field: "time", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "car_images", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.CarImages = CarImages; |
|||
return CarImages; |
|||
}; |
@ -0,0 +1,10 @@ |
|||
'use strict' |
|||
|
|||
const images = require('../../controllers/images') |
|||
|
|||
module.exports = function (app, router, opts, panCode) { |
|||
|
|||
router.get('/car/images', images.getFileCarImages(opts)) |
|||
|
|||
|
|||
} |
@ -0,0 +1,16 @@ |
|||
create table car_images |
|||
( |
|||
id serial |
|||
constraint car_images_pk |
|||
primary key, |
|||
url varchar, |
|||
time timestamptz |
|||
); |
|||
|
|||
comment on column car_images.url is '图片路径'; |
|||
|
|||
comment on column car_images.time is '时间'; |
|||
|
|||
create unique index car_images_id_uindex |
|||
on car_images (id); |
|||
|
@ -0,0 +1,15 @@ |
|||
import { basicAction } from '@peace/utils' |
|||
import { ApiTable } from '$utils' |
|||
|
|||
|
|||
export function getCarImages (query) { |
|||
return dispatch => basicAction({ |
|||
type: 'get', |
|||
dispatch: dispatch, |
|||
actionType: 'GET_CAR_IMAGES', |
|||
url: ApiTable.getCarImages, |
|||
query, |
|||
msg: { error: '获取图片失败' }, |
|||
reducer: { name: 'carimage' } |
|||
}) |
|||
} |
@ -0,0 +1,124 @@ |
|||
import React, { useState, useEffect } from 'react' |
|||
import { connect } from 'react-redux' |
|||
import { getCarImages } from '../actions/carimages' |
|||
import ProTable from '@ant-design/pro-table' |
|||
import { Form, Space, DatePicker, Button, Select, Popconfirm, Image, Tooltip } from 'antd' |
|||
import moment from 'moment' |
|||
|
|||
|
|||
function Carimages (props) { |
|||
const { dispatch, assess, user } = props |
|||
const [query, setQuery] = useState({ page: 1, pageSize: 10, }) |
|||
const [loading, setLoading] = useState(false) |
|||
const [datasource, setdatasource] = useState([]) |
|||
const [dateRange, setDateRange] = useState(['1970-1-1', '2099-12-31']) |
|||
const { RangePicker } = DatePicker |
|||
const [total, settotal] = useState(0) |
|||
const [editAble, setEditAble] = useState(user?.username !== 'SuperAdmin' && user?.userResources?.find(i => i.resourceId === 'ASSESSMANAGE')?.isshow === "true" ? true : '') |
|||
useEffect(() => { |
|||
|
|||
return () => { } |
|||
}, []) |
|||
|
|||
useEffect(() => { |
|||
getData() |
|||
}, [query]) |
|||
|
|||
|
|||
|
|||
|
|||
const getData = () => { |
|||
console.log(query, 'query') |
|||
dispatch(getCarImages({ ...query })).then(res => { |
|||
if (res?.success) { |
|||
setdatasource(res?.payload?.data?.rows) |
|||
settotal(res?.payload?.data?.count) |
|||
} |
|||
}) |
|||
} |
|||
|
|||
|
|||
return ( |
|||
<div> |
|||
<div style={{ marginBottom: '20px', display: 'flex', justifyContent: 'space-between' }}> |
|||
<Form layout="inline" onFinish={(v) => { |
|||
|
|||
setQuery({ |
|||
...query, page: 1, unit: v.unit, startTime: v?.time && moment(v?.time[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss'), |
|||
endTime: v?.time && moment(v?.time[1]).add(1, 'days').endOf('day').format('YYYY-MM-DD HH:mm:ss') |
|||
}) |
|||
}}> |
|||
|
|||
{/* <Form.Item> |
|||
<Button type="primary" htmlType="submit">搜索</Button> |
|||
</Form.Item> */} |
|||
</Form> |
|||
|
|||
{/* <Button type="primary" disabled={editAble} |
|||
onClick={() => { |
|||
setAssessModalVisible(true) |
|||
}}>新增</Button> */} |
|||
</div> |
|||
<ProTable |
|||
columns={[ |
|||
{ |
|||
title: '序号', |
|||
dataIndex: 'id', |
|||
key: 'id', |
|||
defaultSortOrder: 'ascend', |
|||
}, |
|||
{ |
|||
title: '抓拍图片', |
|||
dataIndex: 'url', |
|||
key: 'url', |
|||
render: (t, r) => { |
|||
if (r?.url && r?.id) { |
|||
return <span style={{ marginRight: 10 }}> |
|||
<Image src={r?.url} width={200} /> |
|||
</span> |
|||
} else { |
|||
return '--' |
|||
} |
|||
} |
|||
}, |
|||
{ |
|||
title: '日期', |
|||
dataIndex: 'time', |
|||
key: 'time', |
|||
render: (t, r) => { |
|||
const localTime = moment.utc(r?.time).format('YYYY-MM-DD HH:mm:ss') |
|||
return r?.time ? localTime : '--' |
|||
} |
|||
}, |
|||
]} |
|||
dataSource={datasource || []} |
|||
loading={loading} |
|||
pagination={{ |
|||
total: total || 0, |
|||
pageSize: 10, |
|||
defaultPageSize: 10, |
|||
showSizeChanger: false, |
|||
onChange: (page, pageSize) => { |
|||
setQuery({ |
|||
...query, |
|||
page, |
|||
limit: pageSize |
|||
}) |
|||
} |
|||
}} |
|||
rowKey="key" |
|||
toolBarRender={false} |
|||
search={false} |
|||
/> |
|||
|
|||
</div> |
|||
) |
|||
} |
|||
function mapStateToProps (state) { |
|||
const { auth, assess } = state |
|||
return { |
|||
user: auth.user, |
|||
assess: assess.data || [], |
|||
} |
|||
} |
|||
export default connect(mapStateToProps)(Carimages) |
Loading…
Reference in new issue