Commit a30f21ad authored by zengchao's avatar zengchao
Browse files

-

parent ab4da671
<!--
* @Author: 一日看尽长安花
* @since: 2019-09-09 12:16:28
* @LastEditTime: 2019-09-09 12:16:28
* @LastEditors: 一日看尽长安花
* @Description:
-->
<template> <template>
<div :class="{'hidden':hidden}" class="pagination-container"> <div :class="{ hidden: hidden }" class="pagination-container">
<el-pagination <el-pagination
:background="background" :background="background"
:current-page.sync="currentPage" :current-page.sync="currentPage"
...@@ -15,7 +22,7 @@ ...@@ -15,7 +22,7 @@
</template> </template>
<script> <script>
import { scrollTo } from '@/utils/scroll-to' import { scrollTo } from '@/utils/scroll-to';
export default { export default {
name: 'Pagination', name: 'Pagination',
...@@ -35,7 +42,7 @@ export default { ...@@ -35,7 +42,7 @@ export default {
pageSizes: { pageSizes: {
type: Array, type: Array,
default() { default() {
return [10, 20, 30, 50] return [10, 20, 30, 50];
} }
}, },
layout: { layout: {
...@@ -56,38 +63,38 @@ export default { ...@@ -56,38 +63,38 @@ export default {
} }
}, },
computed: { computed: {
currentPage: { currentPagge: {
get() { get() {
return this.page return this.page;
}, },
set(val) { set(val) {
this.$emit('update:page', val) this.$emit('update:page', val);
} }
}, },
pageSize: { pageSize: {
get() { get() {
return this.limit return this.limit;
}, },
set(val) { set(val) {
this.$emit('update:limit', val) this.$emit('update:limit', val);
} }
} }
}, },
methods: { methods: {
handleSizeChange(val) { handleSizeChange(val) {
this.$emit('pagination', { page: this.currentPage, limit: val }) this.$emit('pagination', { page: this.currentPage, limit: val });
if (this.autoScroll) { if (this.autoScroll) {
scrollTo(0, 800) scrollTo(0, 800);
} }
}, },
handleCurrentChange(val) { handleCurrentChange(val) {
this.$emit('pagination', { page: val, limit: this.pageSize }) this.$emit('pagination', { page: val, limit: this.pageSize });
if (this.autoScroll) { if (this.autoScroll) {
scrollTo(0, 800) scrollTo(0, 800);
} }
} }
} }
} };
</script> </script>
<style scoped> <style scoped>
......
/*
* @Description: In User Settings Edit
* @Author: your name
* @Date: 2019-09-09 12:16:28
* @LastEditTime: 2019-09-09 12:16:28
* @LastEditors: your name
*/
import { constantRoutes } from '@/router'; import { constantRoutes } from '@/router';
import { getRoutes } from '@/api/role'; import { getRoutes } from '@/api/role';
import { default as asyncRoutesMap } from '@/router/maps/index'; import { default as asyncRoutesMap } from '@/router/maps/index';
import { import { deepClone, objectMerge } from '@/utils/index';
deepClone, import { isExists, isNotExists } from '@/utils/object-util';
objectMerge,
isNotNullAndNotUndefined,
} from '@/utils/index';
/** /**
* Use meta.role to determine if the current user has permission * Use meta.role to determine if the current user has permission
...@@ -39,10 +43,10 @@ export function filterAsyncRoutes(routesMap, routes, roles) { ...@@ -39,10 +43,10 @@ export function filterAsyncRoutes(routesMap, routes, roles) {
// 从前端路由表中选出与当前后端路由信息相对应的那条路由信息 // 从前端路由表中选出与当前后端路由信息相对应的那条路由信息
for (let rm of routesMap) { for (let rm of routesMap) {
if ( if (
isNotNullAndNotUndefined(rm.name) && isExists(rm.name) &&
isNotNullAndNotUndefined(route.name) && isExists(route.name) &&
isNotNullAndNotUndefined(rm.path) && isExists(rm.path) &&
isNotNullAndNotUndefined(route.path) && isExists(route.path) &&
(rm.path === route.path || rm.name === route.name) (rm.path === route.path || rm.name === route.name)
) { ) {
// 优先path判断,是因为导航菜单的展开和收起是根据path判断的。 // 优先path判断,是因为导航菜单的展开和收起是根据path判断的。
...@@ -57,7 +61,7 @@ export function filterAsyncRoutes(routesMap, routes, roles) { ...@@ -57,7 +61,7 @@ export function filterAsyncRoutes(routesMap, routes, roles) {
tempRoute.children = filterAsyncRoutes( tempRoute.children = filterAsyncRoutes(
tempRouteMap.children, tempRouteMap.children,
tempRoute.children, tempRoute.children,
roles, roles
); );
} }
// 以后台路由表优先,相同属性覆盖前台路由映射.除去路由路径交由前台控制 // 以后台路由表优先,相同属性覆盖前台路由映射.除去路由路径交由前台控制
...@@ -74,14 +78,14 @@ export function filterAsyncRoutes(routesMap, routes, roles) { ...@@ -74,14 +78,14 @@ export function filterAsyncRoutes(routesMap, routes, roles) {
const state = { const state = {
routes: [], routes: [],
addRoutes: [], addRoutes: []
}; };
const mutations = { const mutations = {
SET_ROUTES: (state, routes) => { SET_ROUTES: (state, routes) => {
state.addRoutes = routes; state.addRoutes = routes;
state.routes = constantRoutes.concat(routes); state.routes = constantRoutes.concat(routes);
}, }
}; };
const actions = { const actions = {
...@@ -95,7 +99,7 @@ const actions = { ...@@ -95,7 +99,7 @@ const actions = {
accessedRoutes = filterAsyncRoutes( accessedRoutes = filterAsyncRoutes(
deepClone(asyncRoutesMap), deepClone(asyncRoutesMap),
asyncRoutes, asyncRoutes,
roles, roles
); );
accessedRoutes.push({ path: '*', redirect: '/404', hidden: true }); accessedRoutes.push({ path: '*', redirect: '/404', hidden: true });
...@@ -106,12 +110,12 @@ const actions = { ...@@ -106,12 +110,12 @@ const actions = {
reject(error); reject(error);
}); });
}); });
}, }
}; };
export default { export default {
namespaced: true, namespaced: true,
state, state,
mutations, mutations,
actions, actions
}; };
/*
* @Description: In User Settings Edit
* @Author: your name
* @Date: 2019-10-11 17:40:57
* @LastEditTime: 2019-10-12 09:24:07
* @LastEditors: Please set LastEditors
*/
/**
* @description: obj不存在。由于js存在undefined 和 null两种特殊的数据类型,认为从空间和引用指向上,只要有一个不存在则判断为不存在。
* @param {Object}
* @return {Boolean}
*/
export function isExists(obj) {
return void 0 === obj || null === obj;
}
/**
* @description: obj存在
* @param {Object}
* @return {Boolean}
*/
export function isNotExists(obj) {
return !isExists(obj);
}
import axios from 'axios' /*
import { MessageBox, Message } from 'element-ui' * @Description: In User Settings Edit
import store from '@/store' * @Author: your name
import { getToken } from '@/utils/auth' * @Date: 2019-09-09 12:16:28
* @LastEditTime: 2019-09-09 12:16:28
* @LastEditors: your name
*/
import axios from 'axios';
import { MessageBox, Message } from 'element-ui';
import store from '@/store';
import { getToken } from '@/utils/auth';
// create an axios instance // create an axios instance
const service = axios.create({ const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
// withCredentials: true, // send cookies when cross-domain requests // withCredentials: true, // send cookies when cross-domain requests
timeout: 5000 // request timeout timeout: 5000 // request timeout
}) });
// request interceptor // request interceptor
service.interceptors.request.use( service.interceptors.request.use(
...@@ -19,16 +26,16 @@ service.interceptors.request.use( ...@@ -19,16 +26,16 @@ service.interceptors.request.use(
// let each request carry token // let each request carry token
// ['Authorization'] see to MDN explain about "HTTP Authorization" // ['Authorization'] see to MDN explain about "HTTP Authorization"
// please modify it according to the actual situation // please modify it according to the actual situation
config.headers['Authorization'] = getToken() config.headers['Authorization'] = getToken();
} }
return config return config;
}, },
error => { error => {
// do something with request error // do something with request error
console.log('request err => ' + error) // for debug console.log('request err => ' + error); // for debug
return Promise.reject(error) return Promise.reject(error);
} }
) );
// response interceptor // response interceptor
service.interceptors.response.use( service.interceptors.response.use(
...@@ -43,7 +50,7 @@ service.interceptors.response.use( ...@@ -43,7 +50,7 @@ service.interceptors.response.use(
* You can also judge the status by HTTP Status Code * You can also judge the status by HTTP Status Code
*/ */
response => { response => {
const res = response.data const res = response.data;
// if the custom code is not 20000, it is judged as an error. // if the custom code is not 20000, it is judged as an error.
if (res.code !== 200) { if (res.code !== 200) {
...@@ -51,7 +58,7 @@ service.interceptors.response.use( ...@@ -51,7 +58,7 @@ service.interceptors.response.use(
message: res.message || 'Error', message: res.message || 'Error',
type: 'error', type: 'error',
duration: 5 * 1000 duration: 5 * 1000
}) });
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired; // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
if (res.code === 50008 || res.code === 50012 || res.code === 50014) { if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
...@@ -66,24 +73,24 @@ service.interceptors.response.use( ...@@ -66,24 +73,24 @@ service.interceptors.response.use(
} }
).then(() => { ).then(() => {
store.dispatch('user/resetToken').then(() => { store.dispatch('user/resetToken').then(() => {
location.reload() location.reload();
}) });
}) });
} }
return Promise.reject(new Error(res.message || 'Error')) return Promise.reject(new Error(res.message || 'Error'));
} else { } else {
return res return res;
} }
}, },
error => { error => {
console.log('response err ==> ' + error) // for debug console.log('response err ==> ' + error); // for debug
Message({ Message({
message: error.message, message: error.message,
type: 'error', type: 'error',
duration: 5 * 1000 duration: 5 * 1000
}) });
return Promise.reject(error) return Promise.reject(error);
} }
) );
export default service export default service;
/*
* @Description: 字符串工具类
* @Author: 一日看尽长安花
* @Date: 2019-10-11 17:40:47
* @LastEditTime: 2019-10-12 09:36:33
* @LastEditors: Please set LastEditors
*/
import { isExists, isNotExists } from '@/utils/object-util';
import { isString, trim } from 'lodash';
/**
* @description: 字符串为空串
* @param {Object}
* @return {Boolean}
*/
export function isBlank(str) {
if (isNotExists(str)) {
if (isString(str)) {
if (trim(str).length === 0) {
return true;
} else {
return false;
}
} else {
throw 'str is not string type';
}
} else {
throw 'str is null';
}
}
/**
* @description: 字符串不为空串
* @param {Object}
* @return {Boolean}
*/
export function isNotBlank(str) {
if (isNotExists(str)) {
if (isString(str)) {
if (trim(str).length > 0) {
return true;
} else {
return false;
}
} else {
throw 'str is not string type';
}
} else {
throw 'str is null';
}
}
<!--
* @Author: ???????
* @since: 2019-09-09 12:16:29
* @LastEditTime: 2019-10-12 17:10:36
* @LastEditors: ???????
* @Description:
-->
<template> <template>
<div class="app-container"> <div class="app-container">
<div class="filter-container"> <div class="filter-container">
<el-input v-model="listQuery.title" placeholder="Title" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" /> <el-input
<el-select v-model="listQuery.importance" placeholder="Imp" clearable style="width: 90px" class="filter-item"> v-model="listQuery.title"
<el-option v-for="item in importanceOptions" :key="item" :label="item" :value="item" /> placeholder="Title"
style="width: 200px;"
class="filter-item"
@keyup.enter.native="handleFilter"
/>
<el-select
v-model="listQuery.importance"
placeholder="Imp"
clearable
style="width: 90px"
class="filter-item"
>
<el-option
v-for="item in importanceOptions"
:key="item"
:label="item"
:value="item"
/>
</el-select> </el-select>
<el-select v-model="listQuery.type" placeholder="Type" clearable class="filter-item" style="width: 130px"> <el-select
<el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.display_name+'('+item.key+')'" :value="item.key" /> v-model="listQuery.type"
placeholder="Type"
clearable
class="filter-item"
style="width: 130px"
>
<el-option
v-for="item in calendarTypeOptions"
:key="item.key"
:label="item.display_name + '(' + item.key + ')'"
:value="item.key"
/>
</el-select> </el-select>
<el-select v-model="listQuery.sort" style="width: 140px" class="filter-item" @change="handleFilter"> <el-select
<el-option v-for="item in sortOptions" :key="item.key" :label="item.label" :value="item.key" /> v-model="listQuery.sort"
style="width: 140px"
class="filter-item"
@change="handleFilter"
>
<el-option
v-for="item in sortOptions"
:key="item.key"
:label="item.label"
:value="item.key"
/>
</el-select> </el-select>
<el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"> <el-button
v-waves
class="filter-item"
type="primary"
icon="el-icon-search"
@click="handleFilter"
>
Search Search
</el-button> </el-button>
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate"> <el-button
class="filter-item"
style="margin-left: 10px;"
type="primary"
icon="el-icon-edit"
@click="handleCreate"
>
Add Add
</el-button> </el-button>
<el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload"> <el-button
v-waves
:loading="downloadLoading"
class="filter-item"
type="primary"
icon="el-icon-download"
@click="handleDownload"
>
Export Export
</el-button> </el-button>
<el-checkbox v-model="showReviewer" class="filter-item" style="margin-left:15px;" @change="tableKey=tableKey+1"> <el-checkbox
v-model="showReviewer"
class="filter-item"
style="margin-left:15px;"
@change="tableKey = tableKey + 1"
>
reviewer reviewer
</el-checkbox> </el-checkbox>
</div> </div>
...@@ -35,19 +104,30 @@ ...@@ -35,19 +104,30 @@
style="width: 100%;" style="width: 100%;"
@sort-change="sortChange" @sort-change="sortChange"
> >
<el-table-column label="ID" prop="id" sortable="custom" align="center" width="80" :class-name="getSortClass('id')"> <el-table-column
label="ID"
prop="id"
sortable="custom"
align="center"
width="80"
:class-name="getSortClass('id')"
>
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.id }}</span> <span>{{ scope.row.id }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="Date" width="150px" align="center"> <el-table-column label="Date" width="150px" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span> <span>{{
scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}')
}}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="Title" min-width="150px"> <el-table-column label="Title" min-width="150px">
<template slot-scope="{row}"> <template slot-scope="{ row }">
<span class="link-type" @click="handleUpdate(row)">{{ row.title }}</span> <span class="link-type" @click="handleUpdate(row)">{{
row.title
}}</span>
<el-tag>{{ row.type | typeFilter }}</el-tag> <el-tag>{{ row.type | typeFilter }}</el-tag>
</template> </template>
</el-table-column> </el-table-column>
...@@ -56,114 +136,210 @@ ...@@ -56,114 +136,210 @@
<span>{{ scope.row.author }}</span> <span>{{ scope.row.author }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column v-if="showReviewer" label="Reviewer" width="110px" align="center"> <el-table-column
v-if="showReviewer"
label="Reviewer"
width="110px"
align="center"
>
<template slot-scope="scope"> <template slot-scope="scope">
<span style="color:red;">{{ scope.row.reviewer }}</span> <span style="color:red;">{{ scope.row.reviewer }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="Imp" width="80px"> <el-table-column label="Imp" width="80px">
<template slot-scope="scope"> <template slot-scope="scope">
<svg-icon v-for="n in +scope.row.importance" :key="n" icon-class="star" class="meta-item__icon" /> <svg-icon
v-for="n in +scope.row.importance"
:key="n"
icon-class="star"
class="meta-item__icon"
/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="Readings" align="center" width="95"> <el-table-column label="Readings" align="center" width="95">
<template slot-scope="{row}"> <template slot-scope="{ row }">
<span v-if="row.pageviews" class="link-type" @click="handleFetchPv(row.pageviews)">{{ row.pageviews }}</span> <span
v-if="row.pageviews"
class="link-type"
@click="handleFetchPv(row.pageviews)"
>
{{ row.pageviews }}
</span>
<span v-else>0</span> <span v-else>0</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="Status" class-name="status-col" width="100"> <el-table-column label="Status" class-name="status-col" width="100">
<template slot-scope="{row}"> <template slot-scope="{ row }">
<el-tag :type="row.status | statusFilter"> <el-tag :type="row.status | statusFilter">
{{ row.status }} {{ row.status }}
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="Actions" align="center" width="230" class-name="small-padding fixed-width"> <el-table-column
<template slot-scope="{row}"> label="Actions"
align="center"
width="230"
class-name="small-padding fixed-width"
>
<template slot-scope="{ row }">
<el-button type="primary" size="mini" @click="handleUpdate(row)"> <el-button type="primary" size="mini" @click="handleUpdate(row)">
Edit Edit
</el-button> </el-button>
<el-button v-if="row.status!='published'" size="mini" type="success" @click="handleModifyStatus(row,'published')"> <el-button
v-if="row.status != 'published'"
size="mini"
type="success"
@click="handleModifyStatus(row, 'published')"
>
Publish Publish
</el-button> </el-button>
<el-button v-if="row.status!='draft'" size="mini" @click="handleModifyStatus(row,'draft')"> <el-button
v-if="row.status != 'draft'"
size="mini"
@click="handleModifyStatus(row, 'draft')"
>
Draft Draft
</el-button> </el-button>
<el-button v-if="row.status!='deleted'" size="mini" type="danger" @click="handleModifyStatus(row,'deleted')"> <el-button
v-if="row.status != 'deleted'"
size="mini"
type="danger"
@click="handleModifyStatus(row, 'deleted')"
>
Delete Delete
</el-button> </el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" /> <pagination
v-show="total > 0"
:total="total"
:page.sync="listQuery.page"
:limit.sync="listQuery.limit"
@pagination="getList"
/>
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible"> <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
<el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="70px" style="width: 400px; margin-left:50px;"> <el-form
ref="dataForm"
:rules="rules"
:model="temp"
label-position="left"
label-width="70px"
style="width: 400px; margin-left:50px;"
>
<el-form-item label="Type" prop="type"> <el-form-item label="Type" prop="type">
<el-select v-model="temp.type" class="filter-item" placeholder="Please select"> <el-select
<el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" /> v-model="temp.type"
class="filter-item"
placeholder="Please select"
>
<el-option
v-for="item in calendarTypeOptions"
:key="item.key"
:label="item.display_name"
:value="item.key"
/>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="Date" prop="timestamp"> <el-form-item label="Date" prop="timestamp">
<el-date-picker v-model="temp.timestamp" type="datetime" placeholder="Please pick a date" /> <el-date-picker
v-model="temp.timestamp"
type="datetime"
placeholder="Please pick a date"
/>
</el-form-item> </el-form-item>
<el-form-item label="Title" prop="title"> <el-form-item label="Title" prop="title">
<el-input v-model="temp.title" /> <el-input v-model="temp.title" />
</el-form-item> </el-form-item>
<el-form-item label="Status"> <el-form-item label="Status">
<el-select v-model="temp.status" class="filter-item" placeholder="Please select"> <el-select
<el-option v-for="item in statusOptions" :key="item" :label="item" :value="item" /> v-model="temp.status"
class="filter-item"
placeholder="Please select"
>
<el-option
v-for="item in statusOptions"
:key="item"
:label="item"
:value="item"
/>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="Imp"> <el-form-item label="Imp">
<el-rate v-model="temp.importance" :colors="['#99A9BF', '#F7BA2A', '#FF9900']" :max="3" style="margin-top:8px;" /> <el-rate
v-model="temp.importance"
:colors="['#99A9BF', '#F7BA2A', '#FF9900']"
:max="3"
style="margin-top:8px;"
/>
</el-form-item> </el-form-item>
<el-form-item label="Remark"> <el-form-item label="Remark">
<el-input v-model="temp.remark" :autosize="{ minRows: 2, maxRows: 4}" type="textarea" placeholder="Please input" /> <el-input
v-model="temp.remark"
:autosize="{ minRows: 2, maxRows: 4 }"
type="textarea"
placeholder="Please input"
/>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false"> <el-button @click="dialogFormVisible = false">
Cancel Cancel
</el-button> </el-button>
<el-button type="primary" @click="dialogStatus==='create'?createData():updateData()"> <el-button
type="primary"
@click="dialogStatus === 'create' ? createData() : updateData()"
>
Confirm Confirm
</el-button> </el-button>
</div> </div>
</el-dialog> </el-dialog>
<el-dialog :visible.sync="dialogPvVisible" title="Reading statistics"> <el-dialog :visible.sync="dialogPvVisible" title="Reading statistics">
<el-table :data="pvData" border fit highlight-current-row style="width: 100%"> <el-table
:data="pvData"
border
fit
highlight-current-row
style="width: 100%"
>
<el-table-column prop="key" label="Channel" /> <el-table-column prop="key" label="Channel" />
<el-table-column prop="pv" label="Pv" /> <el-table-column prop="pv" label="Pv" />
</el-table> </el-table>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button type="primary" @click="dialogPvVisible = false">Confirm</el-button> <el-button type="primary" @click="dialogPvVisible = false">
Confirm
</el-button>
</span> </span>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import { fetchList, fetchPv, createArticle, updateArticle } from '@/api/article' import {
import waves from '@/directive/waves' // waves directive fetchList,
import { parseTime } from '@/utils' fetchPv,
import Pagination from '@/components/Pagination' // secondary package based on el-pagination createArticle,
updateArticle
} from '@/api/article';
import waves from '@/directive/waves'; // waves directive
import { parseTime } from '@/utils';
import Pagination from '@/components/Pagination'; // secondary package based on el-pagination
const calendarTypeOptions = [ const calendarTypeOptions = [
{ key: 'CN', display_name: 'China' }, { key: 'CN', display_name: 'China' },
{ key: 'US', display_name: 'USA' }, { key: 'US', display_name: 'USA' },
{ key: 'JP', display_name: 'Japan' }, { key: 'JP', display_name: 'Japan' },
{ key: 'EU', display_name: 'Eurozone' } { key: 'EU', display_name: 'Eurozone' }
] ];
// arr to obj, such as { CN : "China", US : "USA" } // arr to obj, such as { CN : "China", US : "USA" }
const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => { const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
acc[cur.key] = cur.display_name acc[cur.key] = cur.display_name;
return acc return acc;
}, {}) }, {});
export default { export default {
name: 'ComplexTable', name: 'ComplexTable',
...@@ -175,11 +351,11 @@ export default { ...@@ -175,11 +351,11 @@ export default {
published: 'success', published: 'success',
draft: 'info', draft: 'info',
deleted: 'danger' deleted: 'danger'
} };
return statusMap[status] return statusMap[status];
}, },
typeFilter(type) { typeFilter(type) {
return calendarTypeKeyValue[type] return calendarTypeKeyValue[type];
} }
}, },
data() { data() {
...@@ -198,7 +374,10 @@ export default { ...@@ -198,7 +374,10 @@ export default {
}, },
importanceOptions: [1, 2, 3], importanceOptions: [1, 2, 3],
calendarTypeOptions, calendarTypeOptions,
sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }], sortOptions: [
{ label: 'ID Ascending', key: '+id' },
{ label: 'ID Descending', key: '-id' }
],
statusOptions: ['published', 'draft', 'deleted'], statusOptions: ['published', 'draft', 'deleted'],
showReviewer: false, showReviewer: false,
temp: { temp: {
...@@ -219,53 +398,64 @@ export default { ...@@ -219,53 +398,64 @@ export default {
dialogPvVisible: false, dialogPvVisible: false,
pvData: [], pvData: [],
rules: { rules: {
type: [{ required: true, message: 'type is required', trigger: 'change' }], type: [
timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }], { required: true, message: 'type is required', trigger: 'change' }
title: [{ required: true, message: 'title is required', trigger: 'blur' }] ],
timestamp: [
{
type: 'date',
required: true,
message: 'timestamp is required',
trigger: 'change'
}
],
title: [
{ required: true, message: 'title is required', trigger: 'blur' }
]
}, },
downloadLoading: false downloadLoading: false
} };
}, },
created() { created() {
this.getList() this.getList();
}, },
methods: { methods: {
getList() { getList() {
this.listLoading = true this.listLoading = true;
fetchList(this.listQuery).then(response => { fetchList(this.listQuery).then(response => {
this.list = response.data.items this.list = response.data.items;
this.total = response.data.total this.total = response.data.total;
// Just to simulate the time of the request // Just to simulate the time of the request
setTimeout(() => { setTimeout(() => {
this.listLoading = false this.listLoading = false;
}, 1.5 * 1000) }, 1.5 * 1000);
}) });
}, },
handleFilter() { handleFilter() {
this.listQuery.page = 1 this.listQuery.page = 1;
this.getList() this.getList();
}, },
handleModifyStatus(row, status) { handleModifyStatus(row, status) {
this.$message({ this.$message({
message: '操作Success', message: '操作Success',
type: 'success' type: 'success'
}) });
row.status = status row.status = status;
}, },
sortChange(data) { sortChange(data) {
const { prop, order } = data const { prop, order } = data;
if (prop === 'id') { if (prop === 'id') {
this.sortByID(order) this.sortByID(order);
} }
}, },
sortByID(order) { sortByID(order) {
if (order === 'ascending') { if (order === 'ascending') {
this.listQuery.sort = '+id' this.listQuery.sort = '+id';
} else { } else {
this.listQuery.sort = '-id' this.listQuery.sort = '-id';
} }
this.handleFilter() this.handleFilter();
}, },
resetTemp() { resetTemp() {
this.temp = { this.temp = {
...@@ -276,66 +466,66 @@ export default { ...@@ -276,66 +466,66 @@ export default {
title: '', title: '',
status: 'published', status: 'published',
type: '' type: ''
} };
}, },
handleCreate() { handleCreate() {
this.resetTemp() this.resetTemp();
this.dialogStatus = 'create' this.dialogStatus = 'create';
this.dialogFormVisible = true this.dialogFormVisible = true;
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['dataForm'].clearValidate() this.$refs['dataForm'].clearValidate();
}) });
}, },
createData() { createData() {
this.$refs['dataForm'].validate((valid) => { this.$refs['dataForm'].validate(valid => {
if (valid) { if (valid) {
this.temp.id = parseInt(Math.random() * 100) + 1024 // mock a id this.temp.id = parseInt(Math.random() * 100) + 1024; // mock a id
this.temp.author = 'vue-element-admin' this.temp.author = 'vue-element-admin';
createArticle(this.temp).then(() => { createArticle(this.temp).then(() => {
this.list.unshift(this.temp) this.list.unshift(this.temp);
this.dialogFormVisible = false this.dialogFormVisible = false;
this.$notify({ this.$notify({
title: 'Success', title: 'Success',
message: 'Created Successfully', message: 'Created Successfully',
type: 'success', type: 'success',
duration: 2000 duration: 2000
}) });
}) });
} }
}) });
}, },
handleUpdate(row) { handleUpdate(row) {
this.temp = Object.assign({}, row) // copy obj this.temp = Object.assign({}, row); // copy obj
this.temp.timestamp = new Date(this.temp.timestamp) this.temp.timestamp = new Date(this.temp.timestamp);
this.dialogStatus = 'update' this.dialogStatus = 'update';
this.dialogFormVisible = true this.dialogFormVisible = true;
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['dataForm'].clearValidate() this.$refs['dataForm'].clearValidate();
}) });
}, },
updateData() { updateData() {
this.$refs['dataForm'].validate((valid) => { this.$refs['dataForm'].validate(valid => {
if (valid) { if (valid) {
const tempData = Object.assign({}, this.temp) const tempData = Object.assign({}, this.temp);
tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464 tempData.timestamp = +new Date(tempData.timestamp); // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
updateArticle(tempData).then(() => { updateArticle(tempData).then(() => {
for (const v of this.list) { for (const v of this.list) {
if (v.id === this.temp.id) { if (v.id === this.temp.id) {
const index = this.list.indexOf(v) const index = this.list.indexOf(v);
this.list.splice(index, 1, this.temp) this.list.splice(index, 1, this.temp);
break break;
} }
} }
this.dialogFormVisible = false this.dialogFormVisible = false;
this.$notify({ this.$notify({
title: 'Success', title: 'Success',
message: 'Update Successfully', message: 'Update Successfully',
type: 'success', type: 'success',
duration: 2000 duration: 2000
}) });
}) });
} }
}) });
}, },
handleDelete(row) { handleDelete(row) {
this.$notify({ this.$notify({
...@@ -343,47 +533,55 @@ export default { ...@@ -343,47 +533,55 @@ export default {
message: 'Delete Successfully', message: 'Delete Successfully',
type: 'success', type: 'success',
duration: 2000 duration: 2000
}) });
const index = this.list.indexOf(row) const index = this.list.indexOf(row);
this.list.splice(index, 1) this.list.splice(index, 1);
}, },
handleFetchPv(pv) { handleFetchPv(pv) {
fetchPv(pv).then(response => { fetchPv(pv).then(response => {
this.pvData = response.data.pvData this.pvData = response.data.pvData;
this.dialogPvVisible = true this.dialogPvVisible = true;
}) });
}, },
handleDownload() { handleDownload() {
this.downloadLoading = true this.downloadLoading = true;
import('@/vendor/Export2Excel').then(excel => { import('@/vendor/Export2Excel').then(excel => {
const tHeader = ['timestamp', 'title', 'type', 'importance', 'status'] const tHeader = ['timestamp', 'title', 'type', 'importance', 'status'];
const filterVal = ['timestamp', 'title', 'type', 'importance', 'status'] const filterVal = [
const data = this.formatJson(filterVal, this.list) 'timestamp',
'title',
'type',
'importance',
'status'
];
const data = this.formatJson(filterVal, this.list);
excel.export_json_to_excel({ excel.export_json_to_excel({
header: tHeader, header: tHeader,
data, data,
filename: 'table-list' filename: 'table-list'
}) });
this.downloadLoading = false this.downloadLoading = false;
}) });
}, },
formatJson(filterVal, jsonData) { formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => { return jsonData.map(v =>
if (j === 'timestamp') { filterVal.map(j => {
return parseTime(v[j]) if (j === 'timestamp') {
} else { return parseTime(v[j]);
return v[j] } else {
} return v[j];
})) }
})
);
}, },
getSortClass: function(key) { getSortClass: function(key) {
const sort = this.listQuery.sort const sort = this.listQuery.sort;
return sort === `+${key}` return sort === `+${key}`
? 'ascending' ? 'ascending'
: sort === `-${key}` : sort === `-${key}`
? 'descending' ? 'descending'
: '' : '';
} }
} }
} };
</script> </script>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment