From 8dc370f496aba8f84c105a310361daa7f51bdc9d Mon Sep 17 00:00:00 2001 From: Googleplex Date: Mon, 13 Jan 2020 22:13:21 +0800 Subject: [PATCH] Enhance: Extract timeIdToText & timeFilters to config.js --- react/src/components/ViewUploads.js | 16 +++++----------- react/src/routes/Result.js | 22 ++++++++-------------- react/src/routes/admin/Rank.js | 10 ++-------- react/src/routes/admin/Songs.js | 10 ++-------- react/src/utils/config.js | 18 +++++++++++++++++- 5 files changed, 34 insertions(+), 42 deletions(-) diff --git a/react/src/components/ViewUploads.js b/react/src/components/ViewUploads.js index 224e5271..662c65f2 100644 --- a/react/src/components/ViewUploads.js +++ b/react/src/components/ViewUploads.js @@ -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; @@ -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 }, { diff --git a/react/src/routes/Result.js b/react/src/routes/Result.js index da3d5876..7035dcbc 100644 --- a/react/src/routes/Result.js +++ b/react/src/routes/Result.js @@ -5,6 +5,7 @@ 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 = [ @@ -12,14 +13,10 @@ 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 }, @@ -32,7 +29,7 @@ const columns = [ }, { title: "试听", - width: 180, + width: 150, render: (text, record) => { return ; } @@ -50,7 +47,7 @@ const columns = [ } } ]; -const rank = []; //此处填写投票结果 +const rank = []; //Replace [] with results generated on admin/rank class Result extends React.Component { state = { @@ -92,10 +89,7 @@ class Result extends React.Component {
- + 前往网易云歌单 diff --git a/react/src/routes/admin/Rank.js b/react/src/routes/admin/Rank.js index 93ae9d64..a1b63b89 100644 --- a/react/src/routes/admin/Rank.js +++ b/react/src/routes/admin/Rank.js @@ -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; @@ -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: "曲名" }, diff --git a/react/src/routes/admin/Songs.js b/react/src/routes/admin/Songs.js index 49ff28cb..feffb905 100644 --- a/react/src/routes/admin/Songs.js +++ b/react/src/routes/admin/Songs.js @@ -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 = [ @@ -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 }, { diff --git a/react/src/utils/config.js b/react/src/utils/config.js index 8f534204..2dd3cd5a 100644 --- a/react/src/utils/config.js +++ b/react/src/utils/config.js @@ -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" } + ] };