From b3d2125dc1dd1199a44a78c14f52955dbe22e3af Mon Sep 17 00:00:00 2001 From: Seven Du Date: Tue, 31 Jul 2018 14:52:10 +0800 Subject: [PATCH] refactor(feed): ESLint --- packages/slimkit-plus-feed/.eslintrc.js | 39 ++ packages/slimkit-plus-feed/admin/App.js | 36 +- .../admin/components/Comment.js | 459 +++++++++--------- .../admin/components/DeletedFeed.js | 98 ++-- .../admin/components/Feed.js | 368 +++++++------- .../admin/components/Home.js | 76 ++- .../admin/components/PayControl.js | 51 +- packages/slimkit-plus-feed/admin/main.js | 2 +- packages/slimkit-plus-feed/admin/theme.js | 1 - .../slimkit-plus-feed/admin/utils/balance.js | 4 +- .../admin/utils/dateProcess.js | 24 +- .../slimkit-plus-feed/admin/utils/getQuery.js | 8 +- packages/slimkit-plus-feed/package.json | 6 +- 13 files changed, 572 insertions(+), 600 deletions(-) create mode 100644 packages/slimkit-plus-feed/.eslintrc.js diff --git a/packages/slimkit-plus-feed/.eslintrc.js b/packages/slimkit-plus-feed/.eslintrc.js new file mode 100644 index 000000000..ec349ae3b --- /dev/null +++ b/packages/slimkit-plus-feed/.eslintrc.js @@ -0,0 +1,39 @@ +module.exports = { + "env": { + "browser": true, + "es6": true + }, + "extends": [ + "eslint:recommended", + "plugin:react/recommended" + ], + "parser": "babel-eslint", + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": 2016, + "sourceType": "module" + }, + "plugins": [ + "react" + ], + "rules": { + "indent": [ + "error", + 2 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "single" + ], + "semi": [ + "error", + "always" + ] + } +}; \ No newline at end of file diff --git a/packages/slimkit-plus-feed/admin/App.js b/packages/slimkit-plus-feed/admin/App.js index 365bba87a..dbad0d376 100755 --- a/packages/slimkit-plus-feed/admin/App.js +++ b/packages/slimkit-plus-feed/admin/App.js @@ -5,7 +5,7 @@ */ import React, { Component } from 'react'; -import PropTypes from 'prop-types' +import PropTypes from 'prop-types'; import { matchPath, withRouter } from 'react-router'; import { Route } from 'react-router-dom'; import withStyles from '@material-ui/core/styles/withStyles'; @@ -85,30 +85,30 @@ class App extends Component const { history: { replace } } = this.props; this.setState({ value }); switch (value) { - case 'comments': - replace('/comments'); - break; + case 'comments': + replace('/comments'); + break; - case 'feeds': - replace('/feeds'); - break; + case 'feeds': + replace('/feeds'); + break; - case 'paycontrol': - replace('/paycontrol'); - break; + case 'paycontrol': + replace('/paycontrol'); + break; // case 'deleteComments': // replace('/deleteComments'); // break; - case 'deleteFeeds': - replace('/deleteFeeds'); - break; + case 'deleteFeeds': + replace('/deleteFeeds'); + break; - case 'root': - default: - replace('/'); - break; + case 'root': + default: + replace('/'); + break; } }; @@ -122,7 +122,7 @@ class App extends Component const { classes } = this.props; return (
- + ({ }, drawerImageTitle: { width: `calc(100% - ${theme.spacing.unit * 4}px)`, - position: "absolute", + position: 'absolute', bottom: 0, background: 'rgba(255, 255, 255, .4)', color: '#fff' @@ -111,9 +110,6 @@ const styles = (theme) => ({ cursor: { cursor: 'pointer' }, - chip: { - margin: 4, - }, feedContent: { width: `calc(100% - ${theme.spacing.unit * 4}px)`, wordBreak: 'break-all' @@ -130,6 +126,7 @@ class Comment extends Component { static propTypes = { classes: PropTypes.object.isRequired, + location: PropTypes.object.isRequired, }; state = { @@ -155,7 +152,6 @@ class Comment extends Component loadMoreBtnDisabled: false, // 加载按钮是否禁用 loading: false, // 正在加载 nextPage: null, // 下一页 - pinned: null, currentPage: 1, lastPage: 1, total: 0, @@ -204,25 +200,23 @@ class Comment extends Component ...this.state, comments: comments, del: { comment: null, ing: false } - }) - }).catch( error => { - console.log(error); + }); }); - }; + } handlePushDelete (id) { this.setState({ ...this.state, del: { comment: id, ing: false } - }) - }; + }); + } handlePushClose () { this.setState({ ...this.state, del: { comment: null, ing: false } }); - }; + } handleLoadMoreComments () { const { nextPage = null, comments, pinneds, params } = this.state; @@ -262,11 +256,9 @@ class Comment extends Component loadMoreBtnDisabled, loadMoreBtnText, nextPage: data.nextPage - }) - }).catch( error => { - + }); }); - }; + } // 检测关键字变化 keyWordChanged = (e) => { @@ -276,7 +268,7 @@ class Comment extends Component ...this.state.params, keyword: e.target.value } - }) + }); }; handleStimeChanged = (e) => { @@ -287,14 +279,14 @@ class Comment extends Component ...this.state.params, stime: stime } - }) + }); } - handleSnackbar(snackbar = {}) { + handleSnackbar(snackbar = {}) { this.setState({ ...this.state, snackbar: { ...this.state.snackbar, ...snackbar } }); - }; + } handleEtimeChanged = (e) => { const etime = e.target.value; @@ -307,14 +299,13 @@ class Comment extends Component }); }; - // 选择动态时间段 + // 选择动态时间段 handleTypeChanged = name => event => { let value = event.target.value; - const specialType = ['pinned_type', 'top']; const { params } = this.state; let pinned_etime = params.pinned_etime, - pinned_stime = params.pinned_stime, - pinned_type = params.pinned_type; + pinned_stime = params.pinned_stime, + pinned_type = params.pinned_type; if (name === 'top') { pinned_stime = ''; @@ -349,7 +340,7 @@ class Comment extends Component this.setState({ ...this.state, [name]: value - }) + }); }; handlePinnedEtimeChanged = (e) => { @@ -385,7 +376,7 @@ class Comment extends Component open: true, message: '请至少选择一个时间' } - }) + }); } else { this.setState({ ...this.state, @@ -405,7 +396,7 @@ class Comment extends Component open: true, message: '请至少选择一个时间' } - }) + }); } else { this.setState({ ...this.state, @@ -416,18 +407,28 @@ class Comment extends Component // 删除用户选择 handleRequestDelete = () => { - this.state.params.userName = ''; - this.state.params.user_id = 0; - this.setState(this.state); + this.setState({ + ...this.state, + params: { + ...this.state.params, + userName: '', + user_id: 0, + } + }); this.handleGetDatas(); }; // 获取用户发布的评论 getUserComments = (user, name = '') => { - this.state.params.user_id = user; - this.state.params.userName = name; - this.setState(this.state); + this.setState({ + ...this.state, + params: { + ...this.state.params, + userName: name, + user_id: user, + } + }); this.handleGetDatas(); }; @@ -442,15 +443,15 @@ class Comment extends Component return defaultValue; }, null); - }; + } // 打开一个置顶操作框 handlePinnedOpen (comment) { this.setState({ ...this.state, pinned: comment - }) - }; + }); + } handleRejectOpen(comment) { @@ -460,8 +461,8 @@ class Comment extends Component comment, ing: false } - }) - }; + }); + } feedIdChange = e => { this.setState({ @@ -470,7 +471,7 @@ class Comment extends Component ...this.state.params, feed: e.target.value } - }) + }); }; userUserChange = e => { @@ -480,7 +481,7 @@ class Comment extends Component ...this.state.params, user_id: e.target.value } - }) + }); }; userNameChange = e => { @@ -490,7 +491,7 @@ class Comment extends Component ...this.state.params, userName: e.target.value } - }) + }); }; renderPinnedDom(comment) { @@ -502,25 +503,25 @@ class Comment extends Component return ( expires_at ? - + : - + ); } render () { const { classes } = this.props; - const { drawer, feed, comments = [], del, snackbar, params, customer, pinned_customer, pinned, pinnedDialog } = this.state; + const { drawer, feed, comments = [], del, snackbar, params, customer, pinned_customer, pinned } = this.state; return(
@@ -605,8 +606,8 @@ class Comment extends Component 自定义时间 - : - '' + : + '' } { params.user_id ? @@ -618,8 +619,8 @@ class Comment extends Component className={classes.chip} /> - : - '' + : + '' } - + 评论内容: {comment.body} - + - - this.handlePinnedOpen(comment)} - > - - -
+ + this.handlePinnedOpen(comment)} + > + + +
- this.handlePushDelete(comment.id)} - > - - + this.handlePushDelete(comment.id)} + > + + - - - {this.renderPinnedDom(comment)} - + + + {this.renderPinnedDom(comment)} + - - - ))} + + + ))} - {"自定义查询日期"} + {'自定义查询日期'} 取消 @@ -737,7 +738,7 @@ class Comment extends Component - {"自定义置顶查询日期"} + {'自定义置顶查询日期'} 取消 @@ -828,7 +829,7 @@ class Comment extends Component
); - }; + } /** * 关闭撤销置顶确认窗口 */ @@ -840,19 +841,19 @@ class Comment extends Component comment: null, ing: false } - }) - }; + }); + } handleSnackbarClose () { this.handleSnackbar({ open: false }); - }; - // 关闭动态详情 + } + // 关闭动态详情 handleDrawerClose () { this.setState({ ...this.state, drawer: null, }); - }; + } handleShowFeed = (feed) => { if (feed === this.state.feed.id) { @@ -874,7 +875,7 @@ class Comment extends Component drawer: true, feed: { ...data } }); - }) + }); }; makeDrawerContent(feed) { @@ -911,7 +912,7 @@ class Comment extends Component 文字收费:{paid_node.amount / 100} 元 - ) + ) } {content} @@ -946,56 +947,54 @@ class Comment extends Component } setFeedId (feed_id) { - this.state.params.feed = feed_id; - this.setState(this.state); + this.setState({ params: { ...this.state.params, feed: feed_id } }); this.handleGetDatas(); - }; + } handleOpenPinnedDialog (comment) { this.setState({ - ...this.state, pinned: comment - }) - }; + }); + } handleAcceptPinned (comment) { - let pinned = this.handleGetPinned(comment.id) + let pinned = this.handleGetPinned(comment.id); request.patch( createRequestURI(`comments/${pinned.target}/pinneds/${pinned.id}`), { validateStatus: status => status === 201 } ) - .then(( { data: { data } }) => { - this.handleSnackbar({ - message: '操作成功!', - open: true, - }); - delete data.comment; - this.setState({ - ...this.state, - pinned: null - }) - let index = _.findIndex(this.state.pinneds, { id: pinned.id }); - if(index !== -1) { + .then(( { data: { data } }) => { + this.handleSnackbar({ + message: '操作成功!', + open: true, + }); + delete data.comment; this.setState({ ...this.state, - pinneds: { - ...this.state.pinneds, - [index]: { - ...data + pinned: null + }); + let index = _.findIndex(this.state.pinneds, { id: pinned.id }); + if(index !== -1) { + this.setState({ + ...this.state, + pinneds: { + ...this.state.pinneds, + [index]: { + ...data + } } - } + }); + } + }) + .catch(() => { + this.handleSnackbar({ + message: '操作失败!', + open: true, }); - } - }) - .catch(({ response: { data } }) => { - this.handleSnackbar({ - message: '操作失败!', - open: true, }); - }) - }; + } doPinnedAudit (comment = null) { if (! comment) { @@ -1004,12 +1003,10 @@ class Comment extends Component let pin = this.handleGetPinned(comment.id); - const { classes } = this.props; - if(!pin ) { return (
- {"评论置顶审核操作"} + {'评论置顶审核操作'} 该评论未置顶,如果您要人工置顶,请在下方输入要置顶的天数 @@ -1033,7 +1030,7 @@ class Comment extends Component
- ) + ); } const { @@ -1043,14 +1040,12 @@ class Comment extends Component expires_at = null, amount = 0, day = 0, - target = 0, - id = 0 } = pin; if (expires_at && new Date(expires_at) < new Date()) { return (
- {"评论置顶审核操作"} + {'评论置顶审核操作'} 该评论未置顶,或置顶时间已到,或已经被拒绝了申请,如果您要人工置顶,请在下方输入要置顶的天数 @@ -1074,11 +1069,11 @@ class Comment extends Component
- ) + ); } else if (pin && (expires_at && new Date(expires_at) > new Date())) { return(
- {"评论置顶操作"} + {'评论置顶操作'} 评论作者: {name},{ @@ -1095,11 +1090,11 @@ class Comment extends Component
- ) + ); } else { return(
- {"评论置顶审核操作"} + {'评论置顶审核操作'} 评论作者: {name} 花费 {showAmount(amount)},申请该条评论置顶{day}天时间,是否同意? @@ -1119,20 +1114,20 @@ class Comment extends Component
); } - }; + } handleRequestClose() { this.setState({ ...this.state, pinned: null - }) - }; + }); + } handleDayChange = event => { this.setState({ ...this.state, pinnedDay: event.target.value - }) + }); }; /** * 撤销置顶 @@ -1152,40 +1147,40 @@ class Comment extends Component validateStatus: status => status === 204 } ) - .then( () => { - this.setState({ - ...this.state, - pinned: null - }); - this.handleSnackbar({ - message: '操作成功!', - open: true, - }); - this.handleRequestClose(); - let index = _.findIndex(this.state.pinneds, { target: pinned.target }); - if(index !== -1) { - this.state.pinneds.splice(index, 1); - } + .then( () => { + this.setState({ + ...this.state, + pinned: null + }); + this.handleSnackbar({ + message: '操作成功!', + open: true, + }); + this.handleRequestClose(); + let index = _.findIndex(this.state.pinneds, { target: pinned.target }); + if(index !== -1) { + this.state.pinneds.splice(index, 1); + } - this.setState({ - ...this.state + this.setState({ + ...this.state + }); }) - }) - .catch( () => { - this.setState({ - ...this.state, - pinnedDialog: + .catch( () => { + this.setState({ + ...this.state, + pinnedDialog: { ...this.state.pinnedDialog, ing: false } - }) - this.handleSnackbar({ - message: '操作失败!', - open: true, + }); + this.handleSnackbar({ + message: '操作失败!', + open: true, + }); }); - }) - }; + } /** * 设置置顶 @@ -1207,42 +1202,43 @@ class Comment extends Component validateStatus: status => status === 201 } ) - .then( ({ data: { data } }) => { - this.handleSnackbar({ - message: '设置成功!', - open: true, - }); - this.setState({ - ...this.state, - pinned: null - }); - let index = _.findIndex(this.state.pinneds, {id: data.target}); - if(index !== -1) { - this.state.pinneds[index] = { - ...this.state.pinneds[index], - ...data - }; - } else { - this.state.pinneds.push(data); - } - }) - .catch( () => { - this.handleSnackbar({ - message: '操作失败了!', - open: true, + .then( ({ data: { data } }) => { + this.handleSnackbar({ + message: '设置成功!', + open: true, + }); + let state = this.state; + state.pinned = null; + let index = _.findIndex(this.state.pinneds, {id: data.target}); + if(index !== -1) { + state.pinneds[index] = { + ...this.state.pinneds[index], + ...data + }; + } else { + state.pinneds.push(data); + } + + this.setState(state); + }) + .catch( () => { + this.handleSnackbar({ + message: '操作失败了!', + open: true, + }); }); - }) }; makeImages(images = []) { - switch (images.length) { - case 1: - const file = images.pop(); - return (); + if (images.length) { + let { id } = images.pop(); - default: - return null; + return ( + + ); } + + return null; } handleGetDatas () { @@ -1270,41 +1266,38 @@ class Comment extends Component validateStatus: status => status === 200 } ) - .then(({ data }) => { - if (!data.nextPage) { - loadMoreBtnDisabled = true; - loadMoreBtnText = '已全部加载'; - } else { - loadMoreBtnDisabled = false; - loadMoreBtnText = '加载更多'; - } + .then(({ data }) => { + if (!data.nextPage) { + loadMoreBtnDisabled = true; + loadMoreBtnText = '已全部加载'; + } else { + loadMoreBtnDisabled = false; + loadMoreBtnText = '加载更多'; + } - this.setState({ - comments: data.comments, - pinneds: data.pinneds, - loading: false, - nextPage: data.nextPage, - currentPage: data.current_page, - lastPage: data.lastPage, - total: data.total, - loadMoreBtnDisabled, - loadMoreBtnText + this.setState({ + comments: data.comments, + pinneds: data.pinneds, + loading: false, + nextPage: data.nextPage, + currentPage: data.current_page, + lastPage: data.lastPage, + total: data.total, + loadMoreBtnDisabled, + loadMoreBtnText + }); }); - }) } componentDidMount () { const search = this.props.location.search; if(search) { - let params = {...getQuery(search)}; - params = { - ...this.state.params, - ...params - }; - this.state.params = params; + this.setState({ + params: { ...this.state.params, ...getQuery(search) } + }); } this.handleGetDatas(); - }; + } } export default withStyles(styles)(Comment); \ No newline at end of file diff --git a/packages/slimkit-plus-feed/admin/components/DeletedFeed.js b/packages/slimkit-plus-feed/admin/components/DeletedFeed.js index 28e1c0b8f..88db81f5a 100755 --- a/packages/slimkit-plus-feed/admin/components/DeletedFeed.js +++ b/packages/slimkit-plus-feed/admin/components/DeletedFeed.js @@ -3,7 +3,7 @@ */ import React, { Component } from 'react'; -import PropTypes from 'prop-types' +import PropTypes from 'prop-types'; import withStyles from '@material-ui/core/styles/withStyles'; import Grid from '@material-ui/core/Grid'; @@ -24,18 +24,13 @@ import CircularProgress from '@material-ui/core/CircularProgress'; import Drawer from '@material-ui/core/Drawer'; import Chip from '@material-ui/core/Chip'; import FormControl from '@material-ui/core/FormControl'; -import FormHelperText from '@material-ui/core/FormHelperText'; -import FormControlLabel from '@material-ui/core/FormControlLabel'; -import { Link } from 'react-router-dom'; import Input from '@material-ui/core/Input'; -import InputLabel from '@material-ui/core/InputLabel'; import FavoriteIcon from '@material-ui/icons/Favorite'; import Forum from '@material-ui/icons/Forum'; import Delete from '@material-ui/icons/Delete'; import CloseIcon from '@material-ui/icons/Close'; import SettingsBackupRestore from '@material-ui/icons/SettingsBackupRestore'; -import _ from 'lodash'; import request, { createRequestURI } from '../utils/request'; @@ -57,7 +52,7 @@ const styles = (theme) => ({ }, drawerImageTitle: { width: '100%', - position: "absolute", + position: 'absolute', bottom: 0, background: 'rgba(255, 255, 255, .4)', color: '#fff' @@ -156,7 +151,7 @@ class DeletedFeed extends Component ...this.state.params, keyword: e.target.value } - }) + }); }; handleUserChange = e => { @@ -166,7 +161,7 @@ class DeletedFeed extends Component ...this.state.params, user: e.target.value } - }) + }); }; handleNameChange = e => { @@ -176,7 +171,7 @@ class DeletedFeed extends Component ...this.state.params, name: e.target.value } - }) + }); }; render() { @@ -226,8 +221,8 @@ class DeletedFeed extends Component className={classes.chip} /> - : - '' + : + '' } ) : ( @@ -949,16 +905,15 @@ class Feed extends Component { validateStatus: status => status === 204 }) .then(() => { - this.state.pinned = null; + let state = this.state; + state.pinned = null; let index = _.findIndex(this.state.feeds, { id: feed.id }); - this.state.feeds[index].pinned = null; + state.feeds[index].pinned = null; this.handleSnackbar({ - message: "已拒绝申请", + message: '已拒绝申请', open: true }); - }) - .catch(({ response: { data } }) => { - console.log(data); + this.setState(state); }); } @@ -989,19 +944,23 @@ class Feed extends Component { .delete(createRequestURI(`feeds/${feed.id}/pinned`), { validateStatus: status => status === 204 }) - .then(({ data }) => { + .then(() => { this.handleSnackbar({ - message: "已撤销!", + message: '已撤销!', open: true }); this.handleCloseDeletePinned(); - this.state.pinned = null; + + let state = this.state; + state.pinned = null; let index = _.findIndex(this.state.feeds, { id: feed.id }); - this.state.feeds[index].pinned = null; + state.feeds[index].pinned = null; + + this.setState(state); }) .catch(() => { this.handleSnackbar({ - message: "操作失败!", + message: '操作失败!', open: true }); this.handleCloseDeletePinned(); @@ -1014,7 +973,7 @@ class Feed extends Component { createRequestURI(`pinned/${feed.pinned.id}`), { ...{ - action: "accept" + action: 'accept' } }, { @@ -1022,18 +981,19 @@ class Feed extends Component { } ) .then(({ data }) => { - console.log(data); let index = _.findIndex(this.state.feeds, { id: feed.id }); - this.state.feeds[index].pinned = data; + let state = this.state; + state.feeds[index].pinned = data; this.handleSnackbar({ - message: "操作成功!", + message: '操作成功!', open: true }); this.handleRequestClose(); + this.setState(state); }) .catch(() => { this.handleSnackbar({ - message: "操作失败!", + message: '操作失败!', open: true }); }); @@ -1077,14 +1037,14 @@ class Feed extends Component { this.handlePushClose(); this.handlePullFeed(feed); this.handleSnackbar({ - message: "删除成功!", + message: '删除成功!', open: true }); }) .catch( ({ response: { - data: { message: [message = "删除失败,请检查网络!"] = [] } = {} + data: { message: [message = '删除失败,请检查网络!'] = [] } = {} } = {} } = {}) => { this.handlePushClose(); @@ -1129,12 +1089,12 @@ class Feed extends Component { this.setState({ ...this.state, loadMoreBtnDisabled: true, - loadMoreBtnText: "没有更多了", + loadMoreBtnText: '没有更多了', loading: false, snackbar: { ...this.state.snackbar, open: true, - message: "没有更多了" + message: '没有更多了' } }); return; @@ -1143,12 +1103,12 @@ class Feed extends Component { this.setState({ ...this.state, loading: true, - loadMoreBtnText: "", + loadMoreBtnText: '', loadMoreBtnDisabled: true }); request - .get(createRequestURI("feeds"), { + .get(createRequestURI('feeds'), { params: { ...params, page: params.current_page + 1 @@ -1176,7 +1136,7 @@ class Feed extends Component { this.setState({ ...this.state, loading: false, - loadMoreBtnText: "已加载全部", + loadMoreBtnText: '已加载全部', loadMoreBtnDisabled: true }); return; @@ -1184,7 +1144,7 @@ class Feed extends Component { this.setState({ ...this.state, loading: false, - loadMoreBtnText: "加载更多", + loadMoreBtnText: '加载更多', loadMoreBtnDisabled: false }); }); @@ -1196,31 +1156,31 @@ class Feed extends Component { ...this.state, loading: true, loadMoreBtnDisabled: true, - loadMoreBtnText: "加载中..." + loadMoreBtnText: '加载中...' }); const { params } = this.state; request .get( - createRequestURI("feeds"), + createRequestURI('feeds'), { params: { ...params, - stime: params.stime ? localDateToUTC(params.stime) : "", - etime: params.etime ? localDateToUTC(params.etime) : "", + stime: params.stime ? localDateToUTC(params.stime) : '', + etime: params.etime ? localDateToUTC(params.etime) : '', page: 1 } }, { validateStatus: status => status === 200 } ) .then(({ data }) => { - let loadMoreBtnText = "加载更多", + let loadMoreBtnText = '加载更多', loadMoreBtnDisabled = false, loading = false; if (data.data.length < params.limit) { loadMoreBtnDisabled = true; - loadMoreBtnText = "已加载全部"; + loadMoreBtnText = '已加载全部'; } this.setState({ ...this.state, @@ -1245,12 +1205,12 @@ class Feed extends Component { componentDidMount() { const search = this.props.location.search; if (search) { - let params = { ...getQuery(search) }; - params = { - ...this.state.params, - ...params - }; - this.state.params = params; + this.setState({ + params: { + ...this.state.params, + ...getQuery(search) + } + }); } this.handleGetDatas(); } diff --git a/packages/slimkit-plus-feed/admin/components/Home.js b/packages/slimkit-plus-feed/admin/components/Home.js index a647e9f30..d04cd670a 100755 --- a/packages/slimkit-plus-feed/admin/components/Home.js +++ b/packages/slimkit-plus-feed/admin/components/Home.js @@ -3,19 +3,15 @@ */ import React, { Component } from 'react'; -import PropTypes from 'prop-types' +import PropTypes from 'prop-types'; import withStyles from '@material-ui/core/styles/withStyles'; import Grid from '@material-ui/core/Grid'; import Card from '@material-ui/core/Card'; -import CardHeader from '@material-ui/core/CardHeader'; import CardContent from '@material-ui/core/CardContent'; -import CardMedia from '@material-ui/core/CardMedia'; import CardActions from '@material-ui/core/CardActions'; import Typography from '@material-ui/core/Typography'; import Button from '@material-ui/core/Button'; -import IconButton from '@material-ui/core/IconButton'; -import SvgIcon from '@material-ui/core/SvgIcon'; import { blue } from '@material-ui/core/colors'; import { Link } from 'react-router-dom'; import FormControl from '@material-ui/core/FormControl'; @@ -26,16 +22,11 @@ import DialogContent from '@material-ui/core/DialogContent'; import Dialog from '@material-ui/core/Dialog'; import CircularProgress from '@material-ui/core/CircularProgress'; import Snackbar from '@material-ui/core/Snackbar'; - -import FavoriteIcon from '@material-ui/icons/Favorite'; import Comment from '@material-ui/icons/Comment'; import RssFeed from '@material-ui/icons/RssFeed'; import Radio from '@material-ui/core/Radio'; import RadioGroup from '@material-ui/core/RadioGroup'; -import Popover from '@material-ui/core/Popover'; -import Chip from '@material-ui/core/Chip'; import Drawer from '@material-ui/core/Drawer'; -import Divider from '@material-ui/core/Divider'; import ListSubheader from '@material-ui/core/ListSubheader'; import ListItemText from '@material-ui/core/ListItemText'; import List from '@material-ui/core/List'; @@ -115,16 +106,15 @@ class Home extends Component feeds: data.feedsCount || 0, comments: data.commentsCount || 0, reward: data.status.reward ? 'true' : 'false' - }) - }).catch( error => { - + }); + }).catch( () => { }); - }; + } handleRequestClose = () => { this.setState({ open: false - }) + }); } /** @@ -132,9 +122,10 @@ class Home extends Component * @param {[type]} key [description] * @return {[type]} [description] */ - handleRewardChange = key => (event, value) => { - this.state.close.reward.status = value; - this.setState(this.state); + handleRewardChange = () => (value) => { + let state = this.state; + state.close.reward.status = value; + this.setState(state); if (value === 'true') { this.handleRewardStore(); } @@ -142,41 +133,40 @@ class Home extends Component // 打赏开关控制 handleRewardStore () { - this.state.close.reward.ing = true; - this.setState(this.state); + let state = this.state; + state.close.reward.ing = true; + this.setState(state); const { close: { reward: { status = 'false' } = {} } = {} } = this.state; request.patch(createRequestURI('status/reward'), { reward: status === 'false' ? false : true }, { validataStatus: status => status === 201 }) - .then( () => { - this.state.close.reward.ing = false; - this.state.close.reward.status = 'true'; - this.state.reward = status; - this.state.open = true; - this.setState(this.state); - }) - .catch(({ response: { data = {} } }) => { - console.log(data); - }) - }; + .then( () => { + state.close.reward.ing = false; + state.close.reward.status = 'true'; + state.reward = status; + state.open = true; + this.setState(state); + }); + } handleCloseRewardDialog () { - this.state.close.reward.status = 'true'; - this.state.close.reward.ing = false; - this.setState(this.state); - }; + let state = this.state; + state.close.reward.status = 'true'; + state.close.reward.ing = false; + this.setState(state); + } handleClick = (type) => { request.get(createRequestURI(`statistics?type=${type}`), { validataStatus: status => status === 200 }) - .then(({ data = {} }) => { - this.setState({ - data: { ...data }, - type: type + .then(({ data = {} }) => { + this.setState({ + data: { ...data }, + type: type + }); }); - }) this.setState({ type: type }); @@ -191,7 +181,7 @@ class Home extends Component {this.setState({ drawerOpen: false, type: ''})}} + onRequestClose={() => {this.setState({ drawerOpen: false, type: ''});}} >
动态数据统计}> @@ -388,7 +378,7 @@ class Home extends Component
- + @@ -440,7 +430,7 @@ class Home extends Component diff --git a/packages/slimkit-plus-feed/admin/components/PayControl.js b/packages/slimkit-plus-feed/admin/components/PayControl.js index 11d585ba1..5098b3813 100755 --- a/packages/slimkit-plus-feed/admin/components/PayControl.js +++ b/packages/slimkit-plus-feed/admin/components/PayControl.js @@ -3,19 +3,16 @@ */ import React, { Component } from 'react'; -import PropTypes from 'prop-types' +import PropTypes from 'prop-types'; import Grid from '@material-ui/core/Grid'; import Card from '@material-ui/core/Card'; -import CardHeader from '@material-ui/core/CardHeader'; import CardContent from '@material-ui/core/CardContent'; -import CardMedia from '@material-ui/core/CardMedia'; import CardActions from '@material-ui/core/CardActions'; import Typography from '@material-ui/core/Typography'; import Dialog from '@material-ui/core/Dialog'; import DialogContent from '@material-ui/core/DialogContent'; import DialogActions from '@material-ui/core/DialogActions'; import Snackbar from '@material-ui/core/Snackbar'; -import Avatar from '@material-ui/core/Avatar'; import Button from '@material-ui/core/Button'; import IconButton from '@material-ui/core/IconButton'; import FormControlLabel from '@material-ui/core/FormControlLabel'; @@ -60,23 +57,23 @@ class PayControl extends Component this.setState({ ...this.state, payItems: e.target.value - }) + }); }; handleTextChange = e => { this.setState({ ...this.state, textLength: e.target.value - }) + }); }; - handleSnackbar(snackbar = {}) { + handleSnackbar(snackbar = {}) { this.setState({ ...this.state, snackbar: { ...this.state.snackbar, ...snackbar } }); - }; + } handleSnackbarClose() { this.handleSnackbar({ open: false, }); - }; + } saveItem () { const { payItems, textLength } = this.state; request.patch(createRequestURI('paycontrol'), { @@ -89,16 +86,16 @@ class PayControl extends Component message: '保存成功!', open: true, }); - }).catch ( error => { + }).catch ( () => { this.handleSnackbar({ message: '保存失败!', open: true, }); - }) - }; + }); + } render () { - let { open = false, payItems = '',close, snackbar } = this.state; + let { open = false, close, snackbar } = this.state; const { classes } = this.props; return ( @@ -141,7 +138,7 @@ class PayControl extends Component

发布付费动态时的金额选项,最少为0.01元

少于0.01元时会出现意想不到的支付错误,请慎重填写

-

3个选项,请用半角","隔开

+

3个选项,请用半角","隔开

@@ -154,7 +151,7 @@ class PayControl extends Component margin="normal" /> @@ -181,7 +178,7 @@ class PayControl extends Component margin="normal" /> @@ -218,21 +215,21 @@ class PayControl extends Component ]} />
- ) + ); } - handleSetFalse (checked) { + handleSetFalse () { this.setState({ ...this.state, close: { open: true, ing: false } - }) + }); } handleStatusChange () { - open = !this.state.open; + let open = !this.state.open; if (!open) { this.setState({ ...this.state, @@ -240,7 +237,7 @@ class PayControl extends Component open: true, ing: true } - }) + }); } request.patch(createRequestURI('paycontrol'), { open: open @@ -256,12 +253,12 @@ class PayControl extends Component message: '保存成功!', open: true, }); - }).catch ( error => { + }).catch ( () => { this.handleSnackbar({ message: '保存失败!', open: true, }); - }) + }); } handleCannel () { @@ -270,7 +267,7 @@ class PayControl extends Component open: false, ing: false } - }) + }); } componentDidMount () { @@ -281,10 +278,10 @@ class PayControl extends Component open: data.open, payItems: data.payItems, textLength: data.textLength - }) - }).catch( error => { + }); + }).catch( () => { alert('获取配置信息失败'); - }) + }); } } diff --git a/packages/slimkit-plus-feed/admin/main.js b/packages/slimkit-plus-feed/admin/main.js index 748702c38..04ed094a0 100755 --- a/packages/slimkit-plus-feed/admin/main.js +++ b/packages/slimkit-plus-feed/admin/main.js @@ -13,7 +13,7 @@ import React from 'react'; import { render } from 'react-dom'; import { HashRouter as Router } from 'react-router-dom'; import theme from './theme'; -import { MuiThemeProvider, createMuiTheme, withTheme } from '@material-ui/core/styles'; +import { MuiThemeProvider } from '@material-ui/core/styles'; import CssBaseline from '@material-ui/core/CssBaseline'; import App from 'App'; diff --git a/packages/slimkit-plus-feed/admin/theme.js b/packages/slimkit-plus-feed/admin/theme.js index 1903b64e8..277d95e88 100755 --- a/packages/slimkit-plus-feed/admin/theme.js +++ b/packages/slimkit-plus-feed/admin/theme.js @@ -1,4 +1,3 @@ -import { withTheme } from '@material-ui/core/styles/'; import { createMuiTheme } from '@material-ui/core/styles'; import blue from '@material-ui/core/colors/blue'; import pink from '@material-ui/core/colors/pink'; diff --git a/packages/slimkit-plus-feed/admin/utils/balance.js b/packages/slimkit-plus-feed/admin/utils/balance.js index 0e0193664..ab8e00304 100755 --- a/packages/slimkit-plus-feed/admin/utils/balance.js +++ b/packages/slimkit-plus-feed/admin/utils/balance.js @@ -1,9 +1,9 @@ function showAmount (amount) { - const { walletRatio = 100 } = window.FEED; + const { walletRatio = 100 } = window.FEED; return amount / walletRatio * 100 + '(元)'; } export { showAmount -} \ No newline at end of file +}; \ No newline at end of file diff --git a/packages/slimkit-plus-feed/admin/utils/dateProcess.js b/packages/slimkit-plus-feed/admin/utils/dateProcess.js index b91ff0060..44d82677b 100755 --- a/packages/slimkit-plus-feed/admin/utils/dateProcess.js +++ b/packages/slimkit-plus-feed/admin/utils/dateProcess.js @@ -5,26 +5,26 @@ * @return {String} * @author Seven Du */ - function localDate(value){ - return (new Date(`${value}Z`)).toLocaleString(); - } - /** +function localDate(value){ + return (new Date(`${value}Z`)).toLocaleString(); +} +/** * Local date to UTC. * * @param {String} value * @return {String} * @author Seven Du */ - function localDateToUTC(value) { - const dateRepo = new Date(value); - const fullYear = dateRepo.getUTCFullYear(); - const month = dateRepo.getUTCMonth() + 1; - const date = dateRepo.getUTCDate(); +function localDateToUTC(value) { + const dateRepo = new Date(value); + const fullYear = dateRepo.getUTCFullYear(); + const month = dateRepo.getUTCMonth() + 1; + const date = dateRepo.getUTCDate(); - return `${fullYear}-${month}-${date}`; - } + return `${fullYear}-${month}-${date}`; +} export { localDateToUTC, localDate -} \ No newline at end of file +}; \ No newline at end of file diff --git a/packages/slimkit-plus-feed/admin/utils/getQuery.js b/packages/slimkit-plus-feed/admin/utils/getQuery.js index 5fb5b91f5..ecfebd927 100755 --- a/packages/slimkit-plus-feed/admin/utils/getQuery.js +++ b/packages/slimkit-plus-feed/admin/utils/getQuery.js @@ -1,10 +1,10 @@ export default function queryURL(url){ - var arr1 = url.split("?"); - var params = arr1[1].split("&"); + var arr1 = url.split('?'); + var params = arr1[1].split('&'); var obj = {};//声明对象 for(var i=0;i