Commit 08cd6ac8 authored by 刘松's avatar 刘松

final

parent dec35184
...@@ -12,7 +12,7 @@ let db = {}; ...@@ -12,7 +12,7 @@ let db = {};
const dbpath = process.env.MONGO || "mongodb://127.0.0.1:27017/addwechat?poolSize=100000000"; const dbpath = process.env.MONGO || "mongodb://127.0.0.1:27017/addwechat?poolSize=100000000";
const AuthName = 'l_q6KiRVG4200kwRXIwVfgY1yOIa'; const AuthName = 'l_q6KiRVG4200kwRXIwVfgY1yOIa';
const AuthPass = 'N11ztBU2lExdNOklH2AmX4JOzdIa'; const AuthPass = 'N11ztBU2lExdNOklH2AmX4JOzdIa';
const host = process.env.GO || 'http://192.168.1.131:9912'; const host = process.env.GO || 'http://192.168.1.116:9912';
const deviceHost = process.env.DEVICE || 'http://192.168.1.122:9911'; const deviceHost = process.env.DEVICE || 'http://192.168.1.122:9911';
//const host = "http://192.168.1.122:9912"; //const host = "http://192.168.1.122:9912";
let authorition = ''; let authorition = '';
...@@ -49,10 +49,14 @@ MongoClient.connect(dbpath, (err, conn) => { ...@@ -49,10 +49,14 @@ MongoClient.connect(dbpath, (err, conn) => {
function initMongo() { function initMongo() {
db.collection('account').findOne({username: 'admin'},(e,r) => {
if(e || !r) {
db.collection('account').update({ username: 'admin'},{ $set: { password: md5password('123asd') } }, { upsert: 1},(err,rep) => { db.collection('account').update({ username: 'admin'},{ $set: { password: md5password('123asd') } }, { upsert: 1},(err,rep) => {
console.dir(err); console.dir(err);
console.dir(rep.result); console.dir(rep.result);
}) })
}
});
} }
...@@ -96,7 +100,7 @@ router.get('/ping',async function (req, res) { ...@@ -96,7 +100,7 @@ router.get('/ping',async function (req, res) {
}) })
router.get('/search',async (req, res) => { router.get('/search',async (req, res) => {
let { page = 0, size = 0 } = req.query; let { page = 1, size = 10 } = req.query;
if(page > 0) page -= 1; if(page > 0) page -= 1;
let options = { skip: parseInt(page * size), limit: parseInt(size) }; let options = { skip: parseInt(page * size), limit: parseInt(size) };
let count = await db.collection('filters').count({}) let count = await db.collection('filters').count({})
...@@ -107,7 +111,7 @@ router.get('/search',async (req, res) => { ...@@ -107,7 +111,7 @@ router.get('/search',async (req, res) => {
.toArray(async (err,rep) => { .toArray(async (err,rep) => {
let arrs = await getCount(rep) let arrs = await getCount(rep)
if(err) return res.status(500).json({ error: '数据获取错误' }); if(err) return res.status(500).json({ error: '数据获取错误' });
else return res.status(200).json({ count, list: arrs }); else return res.status(200).json({ count, list: arrs, page: parseInt(page || 0) + 1, size: parseInt(size || 10) });
}); });
}) })
...@@ -136,7 +140,7 @@ router.get('/qrcode',async (req, res) => { ...@@ -136,7 +140,7 @@ router.get('/qrcode',async (req, res) => {
router.get('/tasks',async (req, res) => { router.get('/tasks',async (req, res) => {
let { page = 0, size = 10 } = req.query; let { page = 1, size = 10 } = req.query;
if(page > 0) page -= 1; if(page > 0) page -= 1;
let options = { skip: parseInt(page * size), limit: parseInt(size) }; let options = { skip: parseInt(page * size), limit: parseInt(size) };
let count = await db.collection('taskWrap').count({}) let count = await db.collection('taskWrap').count({})
...@@ -153,14 +157,34 @@ router.get('/tasks',async (req, res) => { ...@@ -153,14 +157,34 @@ router.get('/tasks',async (req, res) => {
return x; return x;
}); });
console.dir(arrs); console.dir(arrs);
return res.status(200).json({ count, list: arrs }); return res.status(200).json({ count, list: arrs, page: parseInt(page || 0) + 1, size: parseInt(size || 10) });
}
});
})
router.get('/task/update',(req, res) => {
let { id, update } = req.query;
let update_body = {};
if(update == 'stop') {
update_body['$set'] = { stop: 1 };
} else {
update_body['$unset'] = { stop: 1 };
}
console.dir(update_body);
db.collection('taskWrap').update({_id: OID(id)}, update_body, (err,rep) => {
if(err) return res.status(500).json({ error: '更新失败,刷新查看' });
else {
db.collection('tasks').update({taskWrapID: OID(id)}, update_body, {multi: 1},(error,rep) => {
if(error) return res.status(500).json({ error: '更新失败,刷新查看' });
else res.status(200).json({ status: 'ok' });
});
} }
}); });
}) })
router.get('/task/detail',async (req, res) => { router.get('/task/detail',async (req, res) => {
let { page = 0, size = 10 , taskWrapID = null} = req.query; let { page = 1, size = 10 , taskWrapID = null} = req.query;
if(page > 0) page -= 1; if(page > 0) page -= 1;
let options = { skip: parseInt(page * size), limit: parseInt(size) }; let options = { skip: parseInt(page * size), limit: parseInt(size) };
let count = await db.collection('tasks').count({ taskWrapID: OID(taskWrapID) }) let count = await db.collection('tasks').count({ taskWrapID: OID(taskWrapID) })
...@@ -169,8 +193,9 @@ router.get('/task/detail',async (req, res) => { ...@@ -169,8 +193,9 @@ router.get('/task/detail',async (req, res) => {
.skip(parseInt(page * size)) .skip(parseInt(page * size))
.limit(parseInt(size)) .limit(parseInt(size))
.toArray(async (err,rep) => { .toArray(async (err,rep) => {
rep = rep.map( x => { delete x.wechat_id; let phone = (x.phone || ['*']); x.phone = phone[0] + '*********' + phone[phone.length - 1]; return x;});
if(err) return res.status(500).json({ error: '数据获取错误' }); if(err) return res.status(500).json({ error: '数据获取错误' });
else return res.status(200).json({ count, list: rep }); else return res.status(200).json({ count, list: rep, page: parseInt(page || 0) + 1, size: parseInt(size || 10) });
}); });
}) })
...@@ -282,13 +307,24 @@ router.get('/is_login_wechat/',async (req, res) => { ...@@ -282,13 +307,24 @@ router.get('/is_login_wechat/',async (req, res) => {
}) })
router.post('/remove',async (req, res) => {
let collection = req.body.collection;
let query = req.body.query;
let rep = await db
.collection(collection)
.remove(query);
return res.status(200).json(rep);
});
router.get('/devices',async (req, res) => { router.get('/devices',async (req, res) => {
console.dir(deviceHost);
axios(deviceHost + '/get_device', { axios(deviceHost + '/get_device', {
method: "GET", method: "GET",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
timeout: 300000 timeout: 300000
}) })
.then(async rep => { .then(async rep => {
console.dir(rep.data);
if(rep.data && rep.data.msg && rep.data.msg.list) { if(rep.data && rep.data.msg && rep.data.msg.list) {
res.status(200).json({ list: rep.data.msg.list }); res.status(200).json({ list: rep.data.msg.list });
} else{ } else{
...@@ -296,6 +332,7 @@ router.get('/devices',async (req, res) => { ...@@ -296,6 +332,7 @@ router.get('/devices',async (req, res) => {
} }
}) })
.catch(err => { .catch(err => {
console.dir(err);
if (err) return res.status(500).json({ error: '获取失败'}); if (err) return res.status(500).json({ error: '获取失败'});
}); });
}) })
...@@ -381,24 +418,24 @@ function generateQueryModel (body) { ...@@ -381,24 +418,24 @@ function generateQueryModel (body) {
let areas = []; let areas = [];
let { ageEnd, ageStart, consumptionDuring, consumptionEnd, consumptionStart, districts, dsgroup, flowDuring, flowEnd, flowStart, sexlist } = body; let { ageEnd, ageStart, consumptionDuring, consumptionEnd, consumptionStart, districts, dsgroup, flowDuring, flowEnd, flowStart, sexlist } = body;
if(!isNaN(ageEnd) && !isNaN(ageStart)) { if(!isNaN(ageEnd) && !isNaN(ageStart)) {
age = [{ attrCode: map2Code['age'], relation: 5, attrValue: ageEnd, condition: 'or' },{ attrCode: map2Code['age'], relation: 3, attrValue: ageStart, condition: 'or' }]; age = [{ attrCode: map2Code['age'], relation: 5, attrValue: ageEnd, condition: 'and' },{ attrCode: map2Code['age'], relation: 3, attrValue: ageStart, condition: 'and' }];
attrs= attrs.concat(age); attrs= attrs.concat(age);
} }
if(!isNaN(consumptionStart) && !isNaN(consumptionEnd)) { if(!isNaN(consumptionStart) && !isNaN(consumptionEnd)) {
if(consumptionDuring === '近三月平均') { if(consumptionDuring === '近三月平均') {
consumption = [{ attrCode: map2Code['consume_3'], relation: 5, attrValue: consumptionEnd, condition: 'or' },{ attrCode: map2Code['consume_3'], relation: 3, attrValue: consumptionStart, condition: 'or' }]; consumption = [{ attrCode: map2Code['consume_3'], relation: 5, attrValue: consumptionEnd, condition: 'and' },{ attrCode: map2Code['consume_3'], relation: 3, attrValue: consumptionStart, condition: 'and' }];
} else { } else {
consumption = [{ attrCode: map2Code['consume_6'], relation: 5, attrValue: consumptionEnd, condition: 'or' },{ attrCode: map2Code['consume_3'], relation: 3, attrValue: consumptionStart, condition: 'or' }]; consumption = [{ attrCode: map2Code['consume_6'], relation: 5, attrValue: consumptionEnd, condition: 'and' },{ attrCode: map2Code['consume_3'], relation: 3, attrValue: consumptionStart, condition: 'and' }];
} }
attrs= attrs.concat(consumption); attrs= attrs.concat(consumption);
} }
if(!isNaN(flowStart) && !isNaN(flowEnd)) { if(!isNaN(flowStart) && !isNaN(flowEnd)) {
if(flowDuring === '近三月平均') { if(flowDuring === '近三月平均') {
flow = [{ attrCode: map2Code['flow_3'], relation: 5, attrValue: flowEnd, condition: 'or' },{ attrCode: map2Code['flow_3'], relation: 3, attrValue: flowStart, condition: 'or' }]; flow = [{ attrCode: map2Code['flow_3'], relation: 5, attrValue: flowEnd, condition: 'and' },{ attrCode: map2Code['flow_3'], relation: 3, attrValue: flowStart, condition: 'and' }];
} else { } else {
flow = [{ attrCode: map2Code['flow_6'], relation: 5, attrValue: flowEnd, condition: 'or' },{ attrCode: map2Code['consume_3'], relation: 3, attrValue: flowStart, condition: 'or' }]; flow = [{ attrCode: map2Code['flow_6'], relation: 5, attrValue: flowEnd, condition: 'and' },{ attrCode: map2Code['consume_3'], relation: 3, attrValue: flowStart, condition: 'and' }];
} }
attrs= attrs.concat(flow); attrs= attrs.concat(flow);
} }
...@@ -418,7 +455,10 @@ function generateQueryModel (body) { ...@@ -418,7 +455,10 @@ function generateQueryModel (body) {
}) })
}) })
} }
if( areas.length ) attrs= attrs.concat(areas); if( areas.length ) attrs = attrs.concat(areas);
if(attrs.length) {
attrs[attrs.length - 1].condition = 'and';
}
return attrs; return attrs;
} }
...@@ -428,15 +468,17 @@ router.post("/model/query", function(req,res) { ...@@ -428,15 +468,17 @@ router.post("/model/query", function(req,res) {
let { access_token } = await generateToken(); let { access_token } = await generateToken();
console.dir(access_token); console.dir(access_token);
let model = generateQueryModel(req.body); let model = generateQueryModel(req.body);
console.dir(JSON.stringify({
requestId: generateRequestID(),
queryModel: [{ attrList: model }],
}));
axios(host + '/modelUserListQuery', { axios(host + '/modelUserListQuery', {
method: "POST", method: "POST",
data: JSON.stringify({ data: JSON.stringify({
requestId: generateRequestID(), requestId: generateRequestID(),
queryModel: [{ attrList: model }], queryModel: [{ attrList: model, groupCondition: 'and' },{
attrList: [{
"attrCode":"K003638",
"relation":8,
"attrValue":"90AAAAAA"
}]
}]
}), }),
timeout: 1000 * 60 * 10, timeout: 1000 * 60 * 10,
headers: { headers: {
...@@ -470,7 +512,7 @@ router.post("/logout",function(req,res) { ...@@ -470,7 +512,7 @@ router.post("/logout",function(req,res) {
db db
.collection('session') .collection('session')
.remove({ _id: OID(sessionID) }, (err, rep) => { .remove({ _id: OID(sessionID) }, (err, rep) => {
if (err || !rep) return res.sendStatus(500); if(err || !rep) return res.sendStatus(500);
res.send({ status: "ok", rep }); res.send({ status: "ok", rep });
}); });
}); });
......
const express = require('express'); const express = require('express');
const cookieParser = require('cookie-parser'); const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
const morgan = require('morgan');
const path = require('path'); const path = require('path');
//const morgan = require('morgan'); //const morgan = require('morgan');
const http = require('http'); const http = require('http');
...@@ -8,6 +9,7 @@ const app = express(); ...@@ -8,6 +9,7 @@ const app = express();
const api = require('./api'); const api = require('./api');
const server = http.Server(app); const server = http.Server(app);
app.use(morgan('short'));
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ app.use(bodyParser.urlencoded({
extended: false extended: false
......
...@@ -1319,6 +1319,11 @@ ...@@ -1319,6 +1319,11 @@
"integrity": "sha1-yrHmEY8FEJXli1KBrqjBzSK/wOM=", "integrity": "sha1-yrHmEY8FEJXli1KBrqjBzSK/wOM=",
"dev": true "dev": true
}, },
"basic-auth": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
"integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg=="
},
"batch": { "batch": {
"version": "0.6.1", "version": "0.6.1",
"resolved": "http://registry.npm.taobao.org/batch/download/batch-0.6.1.tgz", "resolved": "http://registry.npm.taobao.org/batch/download/batch-0.6.1.tgz",
...@@ -5481,6 +5486,18 @@ ...@@ -5481,6 +5486,18 @@
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.1.5.tgz", "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.1.5.tgz",
"integrity": "sha512-emT/tM4ZBinqd6RZok+EzDdtN4LjYJIckv71qQVOEFmvXgT5cperZegVmTgox/1cx4XQu6LJ5ZuIwipP/eKdQg==" "integrity": "sha512-emT/tM4ZBinqd6RZok+EzDdtN4LjYJIckv71qQVOEFmvXgT5cperZegVmTgox/1cx4XQu6LJ5ZuIwipP/eKdQg=="
}, },
"morgan": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
"integrity": "sha512-HQStPIV4y3afTiCYVxirakhlCfGkI161c76kKFca7Fk1JusM//Qeo1ej2XaMniiNeaZklMVrh3vTtIzpzwbpmA==",
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA=="
}
}
},
"move-concurrently": { "move-concurrently": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "http://registry.npm.taobao.org/move-concurrently/download/move-concurrently-1.0.1.tgz", "resolved": "http://registry.npm.taobao.org/move-concurrently/download/move-concurrently-1.0.1.tgz",
...@@ -5854,8 +5871,7 @@ ...@@ -5854,8 +5871,7 @@
"on-headers": { "on-headers": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "http://registry.npm.taobao.org/on-headers/download/on-headers-1.0.1.tgz", "resolved": "http://registry.npm.taobao.org/on-headers/download/on-headers-1.0.1.tgz",
"integrity": "sha1-ko9dD0cNSTQmUepnlLCFfBAGk/c=", "integrity": "sha1-ko9dD0cNSTQmUepnlLCFfBAGk/c="
"dev": true
}, },
"once": { "once": {
"version": "1.4.0", "version": "1.4.0",
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
"lodash": "^4.17.11", "lodash": "^4.17.11",
"moment": "^2.22.2", "moment": "^2.22.2",
"mongodb": "^3.1.6", "mongodb": "^3.1.6",
"morgan": "^1.9.1",
"qs": "^6.5.2", "qs": "^6.5.2",
"vue": "^2.5.17", "vue": "^2.5.17",
"vue-class-component": "^6.0.0", "vue-class-component": "^6.0.0",
......
...@@ -6,6 +6,10 @@ const getTaskList = (size: number, page?: number) => { ...@@ -6,6 +6,10 @@ const getTaskList = (size: number, page?: number) => {
return axios.get(`/api/tasks?page=${page}&size=${size}`); return axios.get(`/api/tasks?page=${page}&size=${size}`);
}; };
const removeTask = (id: string, update: string) => {
return axios.get(`/api/task/update?id=${id}&update=${update}`);
};
const getDetailList = (size: number, page: number, taskWrapID: string) => { const getDetailList = (size: number, page: number, taskWrapID: string) => {
return axios.get(`/api/task/detail?page=${page}&size=${size}&taskWrapID=${taskWrapID}`); return axios.get(`/api/task/detail?page=${page}&size=${size}&taskWrapID=${taskWrapID}`);
}; };
...@@ -25,4 +29,5 @@ export { ...@@ -25,4 +29,5 @@ export {
getTaskList, getTaskList,
createTask, createTask,
getDetailList, getDetailList,
removeTask
}; };
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
</template> </template>
</el-table-column> </el-table-column>
<template v-if='addable || detailable'> <template v-if='addable || detailable || removealbe'>
<el-table-column <el-table-column
fixed="right" fixed="right"
label="操作" label="操作"
...@@ -54,6 +54,17 @@ ...@@ -54,6 +54,17 @@
size="small"> size="small">
详情 详情
</el-button> </el-button>
<template v-if='removeable'>
<el-button
@click.native.prevent="detailRemove(scope.$index)"
type="text"
size="small">
{{
scope.row.stop ? '启动' :'停止'
}}
</el-button>
</template>
</template> </template>
</template> </template>
</el-table-column> </el-table-column>
...@@ -87,6 +98,10 @@ import { Action, State } from 'vuex-class'; ...@@ -87,6 +98,10 @@ import { Action, State } from 'vuex-class';
type: Boolean, type: Boolean,
default: false, default: false,
}, },
removeable: {
type: Boolean,
default: false,
},
addRow: { addRow: {
type: Function, type: Function,
default: () => { default: () => {
...@@ -99,6 +114,12 @@ import { Action, State } from 'vuex-class'; ...@@ -99,6 +114,12 @@ import { Action, State } from 'vuex-class';
// 这里传入要编辑的函数 // 这里传入要编辑的函数
}, },
}, },
detailRemove: {
type: Function,
default: () => {
// 这里传入要编辑的函数
},
},
setRow: { setRow: {
type: Function, type: Function,
default: () => { default: () => {
...@@ -138,24 +159,8 @@ export default class CommonTable extends Vue { ...@@ -138,24 +159,8 @@ export default class CommonTable extends Vue {
} }
public isCallbackCode(num: number) { public isCallbackCode(num: number) {
let str = ''; let str = '';
switch (num) { let map = ['正在添加','已是好友','没有该用户','其他异常'];
case 0: return ((num && map[num]) ? map[num] : '未执行');
str = '添加成功';
break;
case 1:
str = '已是好友';
break;
case 2:
str = '没有该用户';
break;
case 3:
str = '其他异常';
break;
case 100:
str = '未执行';
break;
}
return str;
} }
public searchRoleById(id: string) { public searchRoleById(id: string) {
......
import { Commit } from 'vuex'; import { Commit } from 'vuex';
import { Message } from 'element-ui'; import { Message } from 'element-ui';
import { GET_TASKLIST, CREATE_TASK, GET_DETAILLIST } from '../types'; import { GET_TASKLIST, CREATE_TASK, GET_DETAILLIST, REMOVE_TASK } from '../types';
import { getTaskList, createTask, getDetailList } from '@/api/addTask'; import { getTaskList, createTask, getDetailList, removeTask } from '@/api/addTask';
export interface State { export interface State {
...@@ -44,6 +44,19 @@ const actions = { ...@@ -44,6 +44,19 @@ const actions = {
}); });
}, },
[REMOVE_TASK](
context: { commit: Commit, state: State },
payload: { id: string, update: string },
) {
// 获取角色列表
removeTask(payload.id,payload.update).then((data: any) => {
Message.success(`更新成功`);
}).catch((err: any) => {
Message.error(`更新成功`);
throw(err);
});
},
[GET_DETAILLIST]( [GET_DETAILLIST](
context: { commit: Commit, state: State }, context: { commit: Commit, state: State },
payload: { size: number, taskWrapID: any, page: number }, payload: { size: number, taskWrapID: any, page: number },
...@@ -67,24 +80,22 @@ const actions = { ...@@ -67,24 +80,22 @@ const actions = {
id: string, id: string,
user_id: string, user_id: string,
greet: string, greet: string,
callback: any
}) { }) {
// 创建角色
createTask(payload).then((data) => { createTask(payload).then((data) => {
const result = data.data; const result = data.data;
if (result.list) {
context.commit(CREATE_TASK, result); context.commit(CREATE_TASK, result);
Message.success('创建成功'); Message.success('创建成功');
} else { if(payload.callback) payload.callback(null, result);
Message.error(data.data.msg);
}
}).catch((err) => { }).catch((err) => {
if(payload.callback) payload.callback('创建失败');
throw(err); throw(err);
}); });
}, },
}; };
const mutations = { const mutations = {
[GET_TASKLIST](state: State, data: { list: any[], count: number }) { [GET_TASKLIST](state: State, data: { list: any[], count: number, size: any, page: any }) {
state.dataList = data.list.map( (x: any) => { state.dataList = data.list.map( (x: any) => {
return { return {
name: x.code, name: x.code,
...@@ -94,6 +105,7 @@ const mutations = { ...@@ -94,6 +105,7 @@ const mutations = {
used: x.used || 0, used: x.used || 0,
createdAt: x.createdAt, createdAt: x.createdAt,
_id: x._id, _id: x._id,
stop: x.stop,
}; };
}); });
state.count = data.count; state.count = data.count;
...@@ -101,7 +113,7 @@ const mutations = { ...@@ -101,7 +113,7 @@ const mutations = {
state.size = parseInt(data.size || 10); state.size = parseInt(data.size || 10);
}, },
[GET_DETAILLIST](state: State, data: { list: any[], count: number }) { [GET_DETAILLIST](state: State, data: { list: any[], count: number, size: any, page: any }) {
state.detailData.dataList = data.list.map( (x: any) => { state.detailData.dataList = data.list.map( (x: any) => {
return { return {
number: x.phone, number: x.phone,
......
...@@ -26,7 +26,7 @@ const filterNumberState: State = { ...@@ -26,7 +26,7 @@ const filterNumberState: State = {
dataList: [], dataList: [],
deviceList: [{ label: '1', value: '1'}], deviceList: [{ label: '1', value: '1'}],
count: 0, count: 0,
page: 0, page: 1,
size: 10, size: 10,
}; };
...@@ -67,10 +67,10 @@ const actions = { ...@@ -67,10 +67,10 @@ const actions = {
// 筛选 // 筛选
createFilterList(payload).then((data: any) => { createFilterList(payload).then((data: any) => {
Message.success('创建成功'); Message.success('创建成功');
// payload.callback && payload.callback(); if(payload.callback) payload.callback(null, data);
}).catch((err: any) => { }).catch((err: any) => {
Message.success('创建失败'); Message.error('创建失败');
// payload.callback && payload.callback(); if(payload.callback) payload.callback(err);
throw(err); throw(err);
}); });
}, },
...@@ -98,7 +98,7 @@ const actions = { ...@@ -98,7 +98,7 @@ const actions = {
}; };
const mutations = { const mutations = {
[GET_FILTERLIST](state: State, data: { list: any, count: number }) { [GET_FILTERLIST](state: State, data: { list: any, count: number, size: any, page: any }) {
state.dataList = data.list.map( (x: any) => { state.dataList = data.list.map( (x: any) => {
let filter = ''; let filter = '';
if( x.sexlist ) { if( x.sexlist ) {
......
...@@ -42,7 +42,7 @@ const mutations = { ...@@ -42,7 +42,7 @@ const mutations = {
[LOGIN](state: State, data: { username: string, sessionID: string }) { [LOGIN](state: State, data: { username: string, sessionID: string }) {
state.isLogin = true; state.isLogin = true;
localStorage.setItem('__sessionID', data.sessionID); localStorage.setItem('__sessionID', data.sessionID);
state.account.username = data.username; state.account = data;
// state.dataList = data.rows; // state.dataList = data.rows;
// state.count = data.count; // state.count = data.count;
}, },
......
...@@ -17,6 +17,8 @@ export const GET_WECHAT = 'GET_WECHAT'; ...@@ -17,6 +17,8 @@ export const GET_WECHAT = 'GET_WECHAT';
export const RESET_QRCODE = 'RESET_QRCODE'; export const RESET_QRCODE = 'RESET_QRCODE';
export const RESET_WECHATINFO = 'RESET_WECHATINFO'; export const RESET_WECHATINFO = 'RESET_WECHATINFO';
export const GET_DETAILLIST = 'GET_DETAILLIST'; export const GET_DETAILLIST = 'GET_DETAILLIST';
export const REMOVE_TASK = 'REMOVE_TASK';
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
:tHeadList='tHeadList' :tHeadList='tHeadList'
:detailable='detailable' :detailable='detailable'
:detailRow='detailRow' :detailRow='detailRow'
:detailRemove="detailRemove"
:removeable="removeable"
/> />
<div class="pagination"> <div class="pagination">
<Pagination <Pagination
...@@ -54,7 +56,7 @@ import { Component, Vue } from 'vue-property-decorator'; ...@@ -54,7 +56,7 @@ import { Component, Vue } from 'vue-property-decorator';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { Action, State } from 'vuex-class'; import { Action, State } from 'vuex-class';
import { GET_TASKLIST, CREATE_TASK, GET_DETAILLIST } from '@/store/types'; import { GET_TASKLIST, CREATE_TASK, GET_DETAILLIST, REMOVE_TASK } from '@/store/types';
import CommonTable from '@/components/CommonTable.vue'; import CommonTable from '@/components/CommonTable.vue';
import Pagination from '@/components/Pagination.vue'; import Pagination from '@/components/Pagination.vue';
...@@ -74,6 +76,7 @@ export default class AddTask extends Vue { ...@@ -74,6 +76,7 @@ export default class AddTask extends Vue {
@Action(GET_TASKLIST) public getTasklist: any; @Action(GET_TASKLIST) public getTasklist: any;
@Action(CREATE_TASK) public createTask: any; @Action(CREATE_TASK) public createTask: any;
@Action(GET_DETAILLIST) public getDetailList: any; @Action(GET_DETAILLIST) public getDetailList: any;
@Action(REMOVE_TASK) public removeTask: any;
// 初始化数据 // 初始化数据
...@@ -114,7 +117,7 @@ export default class AddTask extends Vue { ...@@ -114,7 +117,7 @@ export default class AddTask extends Vue {
width: 'auto', width: 'auto',
}]; }];
public detailable = true; public detailable = true;
public removeable = true;
// 分页 // 分页
public page = 1; public page = 1;
public size = 10; public size = 10;
...@@ -125,7 +128,7 @@ export default class AddTask extends Vue { ...@@ -125,7 +128,7 @@ export default class AddTask extends Vue {
public dialog = { public dialog = {
name: '', name: '',
data: {}, data: { _id: null },
index: 0, index: 0,
}; };
...@@ -135,28 +138,41 @@ export default class AddTask extends Vue { ...@@ -135,28 +138,41 @@ export default class AddTask extends Vue {
// 点击表格进行编辑 // 点击表格进行编辑
this.dialog.name = 'taskDetail'; this.dialog.name = 'taskDetail';
this.$data.isDialogShow = true; this.$data.isDialogShow = true;
this.getDetailList({ page:1, size:10 ,taskWrapID: this.addTaskState.dataList[index]._id }); this.dialog.data = this.addTaskState.dataList[index];
this.dialog.index = index;
this.getDetailList({ page:1, size:10 ,taskWrapID: this.dialog.data._id });
}
public detailRemove(index: number) {
// 点击表格进行编辑
let id = this.addTaskState.dataList[index]._id;
let update = this.addTaskState.dataList[index].stop ? 'start' : 'stop'
this.removeTask({ id, update });
}
//this.setDialogData('taskDetail', index); public detailPageChange(page: number) {
this.getDetailList({ page:page, size:10 ,taskWrapID: this.dialog.data._id });
} }
public setDialogData(name: string, index: number) { public detailSizeChange(size: number) {
this.getDetailList({ page:1, size:size ,taskWrapID: this.dialog.data._id });
}
/* public setDialogData(name: string, index: number) {
// 设置弹框数据 // 设置弹框数据
this.dialog.name = name; this.dialog.name = name;
this.$data.isDialogShow = true; this.$data.isDialogShow = true;
this.dialog.data = this.addTaskState.dataList[index]; this.dialog.data = this.addTaskState.dataList[index];
this.dialog.index = index; this.dialog.index = index;
} }*/
// 分页 // 分页
public paginationSizeChange(index: number) { public paginationSizeChange(size: number) {
this.size = index; this.getTasklist({ size: size, page: 1 });
// this.getPermission({ size: this.size, page: this.page });
} }
public paginationPageChange(index: number) { public paginationPageChange(page: number) {
this.page = index; this.getTasklist({ size: this.addTaskState.detailData.size, page: page});
// this.getPermission({ size: this.size, page: this.page });
} }
// 清除表单元素及弹框属性 // 清除表单元素及弹框属性
......
...@@ -202,7 +202,7 @@ ...@@ -202,7 +202,7 @@
</div> </div>
<div class="dialog-footer" slot='footer'> <div class="dialog-footer" slot='footer'>
<el-button type="primary" @click="sumbitAddFilter" >确 定</el-button> <el-button type="primary" @click="sumbitAddFilter" :loading="pending" :disabled="pending">确 定</el-button>
<el-button @click="closeDialog" >取 消</el-button> <el-button @click="closeDialog" >取 消</el-button>
</div> </div>
</el-dialog> </el-dialog>
...@@ -265,7 +265,7 @@ ...@@ -265,7 +265,7 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
<div class="dialog-footer" slot='footer'> <div class="dialog-footer" slot='footer'>
<el-button type="primary" @click="sumbitAddWechat" >确 定</el-button> <el-button type="primary" @click="sumbitAddWechat" :loading="pending" :disabled="pending">确 定</el-button>
<el-button @click="closeDialog" >取 消</el-button> <el-button @click="closeDialog" >取 消</el-button>
</div> </div>
</el-dialog> </el-dialog>
...@@ -337,6 +337,7 @@ export default class FilterNumber extends Vue { ...@@ -337,6 +337,7 @@ export default class FilterNumber extends Vue {
}]; }];
public addable = true; public addable = true;
public deleteable = true; public deleteable = true;
public pending = false;
public area = { public area = {
nation: '全国', nation: '全国',
checkAll: false, checkAll: false,
...@@ -592,33 +593,21 @@ export default class FilterNumber extends Vue { ...@@ -592,33 +593,21 @@ export default class FilterNumber extends Vue {
} }
// 分页 // 分页
public paginationSizeChange(index: number) { public paginationSizeChange(size: number) {
this.size = index; this.getFilterlist({ size: size, page: 1 });
this.getFilterlist({ size: this.size, page: this.page });
} }
public paginationPageChange(index: number) { public paginationPageChange(page: number) {
this.page = index; this.getFilterlist({ size: this.numberFilterState.size, page: page });
this.getFilterlist({ size: this.size, page: this.page });
} }
// 清除表单元素及弹框属性 // 清除表单元素及弹框属性
public cleanDialogForm(form: string) { public cleanDialogForm(form: string) {
//const newform = this.$data[form];
if(form === 'filterForm') this.$refs.filterForm.resetFields(); if(form === 'filterForm') this.$refs.filterForm.resetFields();
else this.$refs.addForm.resetFields(); else this.$refs.addForm.resetFields();
if(form === 'addForm') { if(form === 'addForm') {
this.resetQrcode(); this.resetQrcode();
} }
/* Object.keys(newform).forEach((val, ind) => {
let t = '';
if( val === 'flowDuring' || val === 'consumptionDuring') {
t = '近三月平均';
}
newform[val] = t;
});*/
//console.dir(this.$data[form]);
//console.dir('====> end');
} }
// 弹框 // 弹框
...@@ -668,6 +657,7 @@ export default class FilterNumber extends Vue { ...@@ -668,6 +657,7 @@ export default class FilterNumber extends Vue {
public sumbitAddFilter() { public sumbitAddFilter() {
const form = this.$data.filterForm; const form = this.$data.filterForm;
const area = this.$data.area; const area = this.$data.area;
const self = this;
this.$refs.filterForm.validate((valid: any) => { this.$refs.filterForm.validate((valid: any) => {
if (valid) { if (valid) {
let areas: any = []; let areas: any = [];
...@@ -682,33 +672,44 @@ export default class FilterNumber extends Vue { ...@@ -682,33 +672,44 @@ export default class FilterNumber extends Vue {
} }
}); });
form.districts = areas; form.districts = areas;
form.callback = () => { form.callback = (err: any, data: any) => {
this.cleanDialogForm('filterForm'); self.$data.pending = false;
if(!err){
self.closeDialog();
self.cleanDialogForm('filterForm');
}
} }
self.$data.pending = true;
//console.dir(form); //console.dir(form);
this.createFilter(form).then((data: any) => { this.createFilter(form);
this.closeDialog();
//this.cleanDialogForm('filterForm');
});
} }
}); });
} }
public sumbitAddWechat() { public sumbitAddWechat() {
const form = this.$data.addForm; const form = this.$data.addForm;
const self = this;
this.$refs.addForm.validate((valid: any) => { this.$refs.addForm.validate((valid: any) => {
if (valid) { if (valid) {
if(this.deviceState.weChatInfo && this.deviceState.weChatInfo.wechatId) { if(this.deviceState.weChatInfo && this.deviceState.weChatInfo.wechatId) {
let data = { let data: any = {
count: form.thisTimeAdd, count: form.thisTimeAdd,
id: this.dialog.data._id, id: this.dialog.data._id,
user_id:this.deviceState.weChatInfo.wechatId, user_id:this.deviceState.weChatInfo.wechatId,
greet: form.verificationLanguage, greet: form.verificationLanguage,
} }
this.createTask(data).then((data: any) => { data.callback = (err: any, data: any) => {
self.$data.pending = false;
if(!err){
self.closeDialog();
self.cleanDialogForm('addForm');
}
}
self.$data.pending = true;
this.createTask(data)/*.then((data: any) => {
this.closeDialog(); this.closeDialog();
this.cleanDialogForm('addForm'); this.cleanDialogForm('addForm');
}); });*/
} }
// 提交 // 提交
// this.createPermission(form).then((data: any) => { // this.createPermission(form).then((data: any) => {
...@@ -830,10 +831,10 @@ export default class FilterNumber extends Vue { ...@@ -830,10 +831,10 @@ export default class FilterNumber extends Vue {
this.getQrcode({sn: sn, type: 'get'}); this.getQrcode({sn: sn, type: 'get'});
} else { } else {
this.deviceState.deviceList.forEach((x: any) => { this.deviceState.deviceList.forEach((x: any) => {
if(x.value == value) { if(x.value === value) {
this.resetWechat(x.weChatInfo) this.resetWechat(x.weChatInfo);
} }
}) });
} }
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
</span> </span>
<el-dropdown style="line-height: 60px;float: right;margin: 0px 30px;"> <el-dropdown style="line-height: 60px;float: right;margin: 0px 30px;">
<span class="theme-text"> <span class="theme-text">
{{ currentUser }}<i class="el-icon-arrow-down el-icon--right"></i> {{ account || '~' }}<i class="el-icon-arrow-down el-icon--right"></i>
</span> </span>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<el-dropdown-item> <el-dropdown-item>
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
:unique-opened=true> :unique-opened=true>
<li class="welcome"> <li class="welcome">
<i class="el-icon-people"></i> <i class="el-icon-people"></i>
<span slot="title">Welcome {{ currentUser }}</span> <span slot="title">Welcome {{ account || '~' }}</span>
</li> </li>
<el-menu-item v-for="item in menuItems" :key=item.index @click=routeTo :route=item.index :index=item.index> <el-menu-item v-for="item in menuItems" :key=item.index @click=routeTo :route=item.index :index=item.index>
<i :class=item.icon></i> <i :class=item.icon></i>
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
<script lang="ts"> <script lang="ts">
import { Component, Vue } from 'vue-property-decorator'; import { Component, Vue } from 'vue-property-decorator';
@Component({ @Component({
data() { data() {
return { return {
...@@ -63,11 +64,6 @@ import { Component, Vue } from 'vue-property-decorator'; ...@@ -63,11 +64,6 @@ import { Component, Vue } from 'vue-property-decorator';
}], }],
}; };
}, },
computed: {
currentUser() {
return 'username';
},
},
methods: { methods: {
routeTo() { routeTo() {
// TODO // TODO
...@@ -75,11 +71,17 @@ import { Component, Vue } from 'vue-property-decorator'; ...@@ -75,11 +71,17 @@ import { Component, Vue } from 'vue-property-decorator';
}, },
logout() { logout() {
// TODO // TODO
localStorage.removeItem('__sessionID');
location.href = '/';
}, },
}, },
}) })
export default class Layout extends Vue {} export default class Layout extends Vue {
get account() {
return this.$store.state.login.account.username;
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
Markdown is supported
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