Skip to content

Commit

Permalink
Enhance: Extract timeIdToText & timeFilters to config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
y-young committed Jan 13, 2020
1 parent 50adde7 commit 8dc370f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 42 deletions.
16 changes: 5 additions & 11 deletions react/src/components/ViewUploads.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import React from "react";
import { connect } from "dva";
import { Table } from "antd";

const time = {
"1": "6:30",
"2": "7:00",
"3": "13:45",
"4": "18:40",
"5": "21:35",
"6": "22:30"
};
import { timeIdToText, timeFilters } from "config";

const ViewUploads = ({ upload, loading }) => {
const { songs } = upload;
Expand All @@ -20,8 +12,10 @@ const ViewUploads = ({ upload, loading }) => {
title: "时段",
width: 70,
render: text => {
return time[text];
}
return timeIdToText[text];
},
filters: timeFilters,
onFilter: (value, record) => record.playtime === value
},
{ dataIndex: "name", title: "曲名", width: 200 },
{
Expand Down
22 changes: 8 additions & 14 deletions react/src/routes/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ import { Icon, Tabs, Table, Button } from "antd";
import "aplayer/dist/APlayer.min.css";
import APlayer from "aplayer";
import YPlayer from "components/YPlayer";
import { timeIdToText, timeFilters } from "config";

const TabPane = Tabs.TabPane;
const columns = [
{
dataIndex: "playtime",
title: "时段",
width: 90,
filters: [
{ text: "6:30", value: "1" },
{ text: "7:00", value: "2" },
{ text: "13:45", value: "3" },
{ text: "18:40", value: "4" },
{ text: "21:35", value: "5" },
{ text: "22:30", value: "6" }
],
render: text => {
return timeIdToText[text];
},
filters: timeFilters,
onFilter: (value, record) => record.playtime === value
},
{ dataIndex: "name", title: "曲名", width: 200 },
Expand All @@ -32,7 +29,7 @@ const columns = [
},
{
title: "试听",
width: 180,
width: 150,
render: (text, record) => {
return <YPlayer src={record.url} mini />;
}
Expand All @@ -50,7 +47,7 @@ const columns = [
}
}
];
const rank = []; //此处填写投票结果
const rank = []; //Replace [] with results generated on admin/rank

class Result extends React.Component {
state = {
Expand Down Expand Up @@ -92,10 +89,7 @@ class Result extends React.Component {
</TabPane>
</Tabs>
<br />
<a
href="http://music.163.com/playlist/2621168336"
className="redirect"
>
<a href="http://music.163.com/playlist/2621168336" className="redirect">
前往网易云歌单
<Icon type="arrow-right" />
</a>
Expand Down
10 changes: 2 additions & 8 deletions react/src/routes/admin/Rank.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { connect } from "dva";
import { Table, Button, Input, Form, Modal } from "antd";
import { timeFilters } from "config";

const { TextArea } = Input;
const FormItem = Form.Item;
Expand All @@ -10,14 +11,7 @@ const columns = [
dataIndex: "playtime",
title: "时段",
width: "70px",
filters: [
{ text: "6:30", value: "1" },
{ text: "7:00", value: "2" },
{ text: "13:45", value: "3" },
{ text: "18:40", value: "4" },
{ text: "21:35", value: "5" },
{ text: "22:30", value: "6" }
],
filters: timeFilters,
onFilter: (value, record) => record.playtime === value
},
{ dataIndex: "name", title: "曲名" },
Expand Down
10 changes: 2 additions & 8 deletions react/src/routes/admin/Songs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { connect } from "dva";
import { Table, Icon, Button, Input, Form, Tag, Select, Modal } from "antd";
import { TimeSelector } from "components/admin";
import { timeFilters } from "config";

const FormItem = Form.Item;
const colors = [
Expand Down Expand Up @@ -254,14 +255,7 @@ class Songs extends React.Component {
dataIndex: "playtime",
title: "时段",
width: "70px",
filters: [
{ text: "6:30", value: "1" },
{ text: "7:00", value: "2" },
{ text: "13:45", value: "3" },
{ text: "18:40", value: "4" },
{ text: "21:35", value: "5" },
{ text: "22:30", value: "6" }
],
filters: timeFilters,
onFilter: (value, record) => record.playtime === value
},
{
Expand Down
18 changes: 17 additions & 1 deletion react/src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,21 @@ module.exports = {
upload: "/upload",
uploads: "/uploads"
},
voteTexts: ["未投票", "非常不合适", "不合适", "中立", "合适", "非常合适"]
voteTexts: ["未投票", "非常不合适", "不合适", "中立", "合适", "非常合适"],
timeIdToText: {
"1": "6:30",
"2": "7:00",
"3": "13:45",
"4": "18:40",
"5": "21:35",
"6": "22:30"
},
timeFilters: [
{ text: "6:30", value: "1" },
{ text: "7:00", value: "2" },
{ text: "13:45", value: "3" },
{ text: "18:40", value: "4" },
{ text: "21:35", value: "5" },
{ text: "22:30", value: "6" }
]
};

0 comments on commit 8dc370f

Please sign in to comment.