169 lines
4.7 KiB
JavaScript
169 lines
4.7 KiB
JavaScript
apiready = function() {
|
|
|
|
var ctrl = {
|
|
init: {},
|
|
bind: {},
|
|
logout: {},
|
|
// roleList: [],
|
|
}
|
|
|
|
//初始化
|
|
ctrl.init = function() {
|
|
$api.attr($api.dom("#user-head"), "src", $api.getStorage("userHead"));
|
|
$api.text($api.dom("#real-name"), $api.getStorage("realName"));
|
|
|
|
// add s 2023/7/10
|
|
// if ($api.getStorage("userType") == 2) { // 员工
|
|
// ctrl.roleList = $api.getStorage("roleList")
|
|
|
|
// // 显示角色列表
|
|
// $('#role-list').css('display', 'block')
|
|
// // 渲染角色列表
|
|
// ctrl.renderRoleList()
|
|
// }
|
|
// add e 2023/7/10
|
|
|
|
this.bind();
|
|
}
|
|
|
|
//事件绑定
|
|
ctrl.bind = function() {
|
|
// add by guoyuanyuan 2018/9/25
|
|
// 监听客户改变的消息(项目改变)
|
|
api.addEventListener({
|
|
name: 'projectChanged'
|
|
}, function(ret, err) {
|
|
$api.attr($api.dom("#user-head"), "src", $api.getStorage("userHead"));
|
|
$api.text($api.dom("#real-name"), $api.getStorage("realName"));
|
|
});
|
|
//点击退出登录
|
|
|
|
$api.addEvt($api.dom("#logout"), "touchend", function(e) {
|
|
api.closeDrawerPane();
|
|
api.sendEvent({
|
|
name: 'leftPanelClicklogout',
|
|
});
|
|
|
|
}, false);
|
|
|
|
//图像加载失败
|
|
$api.addEvt($api.dom('#user-head'), "error", function() {
|
|
$api.attr(this, "src", "../../image/left-panel-logo.png")
|
|
})
|
|
|
|
//点击修改密码
|
|
|
|
$api.addEvt($api.dom('#chang-pwd'), "touchend", function() {
|
|
api.closeDrawerPane();
|
|
var cus = $api.getStorage('cus');
|
|
if (cus == 1) {
|
|
api.sendEvent({
|
|
name: 'changePwdTip'
|
|
});
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
api.openWin({
|
|
name: 'chang-pwd',
|
|
url: '../../html/user/updatePassword.html'
|
|
});
|
|
|
|
}, false);
|
|
|
|
//点击清空缓存
|
|
$api.addEvt($api.dom('#clear'), "touchend", function() {
|
|
api.closeDrawerPane();
|
|
api.sendEvent({
|
|
name: 'leftPanelClickClear'
|
|
});
|
|
|
|
}, false);
|
|
|
|
//点击了关于我们
|
|
$api.addEvt($api.dom('#about'), "touchend", function() {
|
|
api.openWin({
|
|
name: 'about',
|
|
url: '../../html/about.html'
|
|
});
|
|
|
|
api.closeDrawerPane();
|
|
}, false);
|
|
|
|
// add s
|
|
// 角色切换
|
|
// 1、需要重新获取当前角色下所包含的配电室列表
|
|
// 2、需要重新获取当前角色下的报警列表
|
|
// 添加事件
|
|
$("#role-list").on("touchend", ".role-item", function () {
|
|
// 取消选中
|
|
$("#role-list .role-item").forEach(function (item, index) {
|
|
$api.removeCls(item, "role-item-active");
|
|
})
|
|
|
|
// 选中当前
|
|
$api.addCls(this, "role-item-active");
|
|
|
|
// 更新 localStorage 种保存的 roleId
|
|
$api.setStorage("roleId", $(this).data('id'))
|
|
|
|
// 重新获取配电室列表,重新获取报警列表
|
|
api.sendEvent({
|
|
name: 'roleChanged'
|
|
});
|
|
|
|
})
|
|
// add e
|
|
}
|
|
|
|
ctrl.renderRoleList = function () {
|
|
$('#role-list').empty();
|
|
|
|
var len = ctrl.roleList.length;
|
|
var dom = ''
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
var roleItem = ctrl.roleList[i];
|
|
var tpl = '';
|
|
|
|
tpl += '<li class="role-item {{active}}" data-id="{{roleId}}">'
|
|
tpl += '<span><i></i></span>'
|
|
tpl += '<b>{{roleName}}</b>'
|
|
tpl += '</li>'
|
|
|
|
// 默认选中第一个角色
|
|
if (i == 0) {
|
|
tpl = tpl.replace('{{active}}', 'role-item-active')
|
|
} else {
|
|
tpl = tpl.replace('{{active}}', '')
|
|
}
|
|
|
|
dom += tpl.replace('{{roleId}}', roleItem.roleId)
|
|
.replace('{{roleName}}', roleItem.roleName)
|
|
|
|
}
|
|
|
|
$api.html($api.dom('#role-list'), dom);
|
|
|
|
// // 添加事件
|
|
// $("#role-list").on("touchend", ".role-item", function () {
|
|
// // 取消选中
|
|
// $("#role-list .role-item").forEach(function (item, index) {
|
|
// $api.removeCls(item, "role-item-active");
|
|
// })
|
|
|
|
// // 选中当前
|
|
// $api.addCls(this, "role-item-active");
|
|
|
|
// // 更新 localStorage 种保存的 roleId
|
|
// $api.setStorage("roleId", $(this).data('id'))
|
|
|
|
// // TODO 重新获取配电室列表
|
|
|
|
// })
|
|
}
|
|
|
|
ctrl.init();
|
|
}
|