Skip to content

Commit 570d5ce

Browse files
committed
优化代码
1 parent 863bbf8 commit 570d5ce

File tree

9 files changed

+359
-311
lines changed

9 files changed

+359
-311
lines changed
Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,63 @@
1-
<div id="chooseAppModel" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="chooseAppModelLabel"
2-
aria-hidden="true">
1+
<div id="chooseAppModel" class="modal fade" role="dialog" aria-labelledby="chooseAppModelLabel" aria-hidden="true">
32
<div class="modal-dialog modal-lg">
43
<div class="modal-content">
54
<div class="modal-header">
65
<h3 class="modal-title" id="chooseAppModelLabel">
7-
<span><vc:i18n name="选择应用" namespace="chooseApp"></vc:i18n></span>
6+
<vc:i18n name="选择应用" namespace="chooseApp"></vc:i18n>
87
</h3>
98
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
109
<span aria-hidden="true">&times;</span>
1110
</button>
1211
</div>
1312
<div class="modal-body">
14-
<div class=" row">
15-
<div class="col-lg-12">
16-
<div class="ibox ">
17-
<div class="row">
18-
<div class="col-sm-7 m-b-xs">
19-
</div>
20-
<div class="col-sm-5">
21-
<div class="input-group">
22-
<input :placeholder="vc.i18n('输入应用名称','chooseApp')" type="text"
23-
v-model="chooseAppInfo._currentAppName"
24-
class="form-control form-control-sm">
25-
<span class="input-group-append">
26-
<button type="button" class="btn btn-sm btn-primary"
27-
v-on:click="queryApps()">
28-
<span><vc:i18n name="查询" namespace="chooseApp"></vc:i18n></span>
29-
</button>
30-
</span>
31-
</div>
32-
</div>
33-
</div>
34-
<div class="table-responsive" style="margin-top:15px">
35-
<table class="table table-striped">
36-
<thead>
37-
<tr>
38-
<th>
39-
<span><vc:i18n name="应用" namespace="chooseApp"></vc:i18n></span>Id
40-
</th>
41-
<th>
42-
<span><vc:i18n name="应用名称" namespace="chooseApp"></vc:i18n></span>
43-
</th>
44-
<th>
45-
<span><vc:i18n name="操作" namespace="chooseApp"></vc:i18n></span>
46-
</th>
47-
</tr>
48-
</thead>
49-
<tbody>
50-
<tr v-for="app in chooseAppInfo.apps">
51-
<td>{{app.appId}}</td>
52-
<td>{{app.name}}</td>
53-
<td>
54-
<button class="btn btn-primary btn-xs" v-on:click="chooseApp(app)">
55-
<span><vc:i18n name="选择" namespace="chooseApp"></vc:i18n></span>
56-
</button>
57-
</td>
58-
</tr>
59-
</tbody>
60-
</table>
61-
<!-- 分页 -->
62-
<vc:create namespace="chooseApp" path="frame/paginationPlus"></vc:create>
13+
<div class="ibox ">
14+
<div class="row">
15+
<div class="col-sm-7 m-b-xs">
16+
</div>
17+
<div class="col-sm-5">
18+
<div class="input-group">
19+
<input :placeholder="vc.i18n('输入应用名称','chooseApp')" type="text"
20+
v-model="chooseAppInfo._currentAppName" class="form-control form-control-sm">
21+
<span class="input-group-append">
22+
<button type="button" class="btn btn-sm btn-primary" v-on:click="queryApps()">
23+
<vc:i18n name="查询" namespace="chooseApp"></vc:i18n>
24+
</button>
25+
</span>
6326
</div>
6427
</div>
6528
</div>
29+
<div class="table-responsive" style="margin-top:15px">
30+
<table class="table table-striped">
31+
<thead>
32+
<tr>
33+
<th>
34+
<vc:i18n name="应用Id" namespace="chooseApp"></vc:i18n>
35+
</th>
36+
<th>
37+
<vc:i18n name="应用名称" namespace="chooseApp"></vc:i18n>
38+
</th>
39+
<th>
40+
<vc:i18n name="操作" namespace="chooseApp"></vc:i18n>
41+
</th>
42+
</tr>
43+
</thead>
44+
<tbody>
45+
<tr v-for="app in chooseAppInfo.apps">
46+
<td>{{app.appId}}</td>
47+
<td>{{app.name}}</td>
48+
<td>
49+
<button class="btn btn-primary btn-xs" v-on:click="chooseApp(app)">
50+
<vc:i18n name="选择" namespace="chooseApp"></vc:i18n>
51+
</button>
52+
</td>
53+
</tr>
54+
</tbody>
55+
</table>
56+
<!-- 分页 -->
57+
<vc:create namespace="chooseApp" path="frame/paginationPlus"></vc:create>
58+
</div>
6659
</div>
6760
</div>
6861
</div>
6962
</div>
70-
</div>
63+
</div>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div>
2-
<!-- 只是负责数据加载 -->
3-
</div>
1+
<div >
2+
3+
</div>

public/components/frame/initData/initData.js

Lines changed: 82 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,74 @@
1-
(function(vc) {
1+
(function (vc) {
22
vc.extends({
33
data: {
4-
initDataInfo: {}
4+
initDataInfo: {
5+
loginUsers: [],
6+
pageUrl: ''
7+
}
58
},
6-
_initMethod: function() {
9+
_initMethod: function () {
710

811
},
9-
_initEvent: function() {
10-
vc.on('initData', 'loadCommunityInfo', function(_param) {
11-
12-
vc.component._validateHasStore(_param);
12+
_initEvent: function () {
13+
vc.on('initData', 'loadCommunityInfo', function (_param) {
14+
$that.loginInfo.loginUsers = _param.loginUsers;
15+
$that.loginInfo.pageUrl = _param.url;
16+
if ($that.loginInfo.loginUsers.length > 1) {
17+
$that._initOpenModal();
18+
return;
19+
}
20+
$that._initLoginUserInfo($that.loginInfo.loginUsers[0]);
1321
})
1422
},
1523
methods: {
16-
_loadCommunityInfo: function(_param) {
17-
var param = {
24+
_initOpenModal: function () {
25+
var content = '<div style="padding: 20px;">';
26+
content += '<table class="layui-table">';
27+
content += '<thead><tr><th>选择</th><th>账号</th><th>隶属</th><th>角色</th></tr></thead>';
28+
content += '<tbody>';
29+
$that.loginInfo.loginUsers.forEach(function (item) {
30+
content += `<tr>
31+
<td><input type="radio" name="selectedItem" value='${JSON.stringify(item)}'></td>
32+
<td>${item.userName}(${item.userId})</td>
33+
<td>${item.storeName}</td>
34+
<td>${item.relCdName}</td>
35+
</tr>`;
36+
});
37+
content += '</tbody></table>';
38+
content += '</div>';
39+
40+
// 打开弹框
41+
layer.open({
42+
type: 1,
43+
title: '请选择账号',
44+
content: content,
45+
area: ['600px', '400px'],
46+
btn: ['确定', '取消'],
47+
yes: function (index, layero) {
48+
// 获取用户选择的数据
49+
let selected = document.querySelector('input[name="selectedItem"]:checked');
50+
if (selected) {
51+
let selectedData = JSON.parse(selected.value);
52+
$that._initLoginUserInfo(selectedData);
53+
54+
} else {
55+
vc.toast('请选择');
56+
}
57+
layer.close(index); // 关闭弹框
58+
},
59+
btn2: function (index, layero) {
60+
layer.close(index); // 关闭弹框
61+
}
62+
});
63+
},
64+
_initLoginUserInfo: function (_user) {
65+
vc.saveData('hc_accessToken', {
66+
token: _user.token
67+
});
68+
$that._validateHasStore();
69+
},
70+
_loadCommunityInfo: function () {
71+
let param = {
1872
params: {
1973
_uId: 'ccdd00opikookjuhyyttvhnnjuuu',
2074
page: 1,
@@ -23,49 +77,48 @@
2377
};
2478
vc.http.apiGet('/community.listMyEnteredCommunitys',
2579
param,
26-
function(json, res) {
27-
if (res.status == 200) {
28-
var _communityInfos = JSON.parse(json).communitys;
29-
if (_communityInfos != null && _communityInfos.length > 0) {
80+
function (json, res) {
81+
let _json = JSON.parse(json);
82+
if (_json.code == 0) {
83+
let _communityInfos = _json.communitys;
84+
if (_communityInfos && _communityInfos.length > 0) {
3085
vc.setCurrentCommunity(_communityInfos[0]);
3186
vc.setCommunitys(_communityInfos);
3287
} else {
3388
vc.toast('运营团队未分配小区,请联系运营团队');
3489
return;
3590
}
36-
vc.jumpToPage(_param.url);
91+
vc.jumpToPage($that.loginInfo.pageUrl);
3792
}
3893
},
39-
function() {
40-
console.log('请求失败处理');
41-
vc.jumpToPage(_param.url);
94+
function () {
95+
vc.jumpToPage($that.loginInfo.pageUrl);
4296
}
4397
);
4498
},
45-
_validateHasStore: function(_param) {
46-
var param = {
99+
_validateHasStore: function () {
100+
let param = {
47101
params: {
48102
_uId: 'ccdd00opikookjuhyyttvhnnjuuu'
49103
}
50104
};
51105
vc.http.apiGet('/query.store.byuser',
52106
param,
53-
function(json, res) {
107+
function (json, res) {
54108
if (res.status == 200) {
55-
$that._loadStaffPrivileges(_param);
56-
//vc.component._loadCommunityInfo(_param);
109+
$that._loadStaffPrivileges();
57110
} else {
58111
vc.toast(json);
59112
}
60113
},
61-
function(e, res) {
114+
function (e, res) {
62115
console.log('请求失败处理', e);
63116
//vc.jumpToPage(_param.url);
64117
vc.toast(e);
65118
}
66119
);
67120
},
68-
_loadStaffPrivileges: function(_param) {
121+
_loadStaffPrivileges: function (_param) {
69122

70123
let param = {
71124
params: {
@@ -75,18 +128,18 @@
75128
//发送get请求
76129
vc.http.apiGet('/query.user.privilege',
77130
param,
78-
function(json) {
79-
let _staffPrivilegeInfo = JSON.parse(json);
131+
function (json) {
132+
let _json = JSON.parse(json);
80133

81134
let _privilege = [];
82-
_staffPrivilegeInfo.datas.forEach(item => {
135+
_json.datas.forEach(item => {
83136
_privilege.push(item.pId);
84137
});
85138

86139
vc.saveData('hc_staff_privilege', _privilege);
87-
vc.component._loadCommunityInfo(_param);
140+
$that._loadCommunityInfo();
88141
},
89-
function() {
142+
function () {
90143
console.log('请求失败处理');
91144
});
92145
},

0 commit comments

Comments
 (0)