TG-PlatformPlus/qml/UserManager.qml

313 lines
9.7 KiB
QML
Raw Permalink Normal View History

2026-03-02 14:29:58 +08:00
import QtQuick
import QtQuick.Dialogs
import QtQuick.Controls
import "./common"
// import "./Style"
Dialog{
id: self
width: 760
height: 450
title: "用户管理"
standardButtons: Dialog.NoButton
// modality: Qt.ApplicationModal
property var userModel: ListModel{}
signal showDialog
onVisibleChanged: {
if(visible)
{
get_users()
showDialog()
}
}
function get_users()
{
var result = backend_proxy.get_users()
if(result.code !== 200)
{
alert.show(result.msg)
return
}
userModel.clear()
result.data.forEach(function(item){
item.role_name = ""
userModel.append(item)
})
}
function add_user()
{
var obj = {"name":"新用户", "password": "000000", "role": 1}
var result = backend_proxy.add_user(JSON.stringify(obj))
if(result.code !== 200)
{
alert.show(result.msg)
return
}
var item = result.data
item.role_name = ""
userModel.append(item)
}
function delete_user()
{
var obj = userModel.get(userTableView.currentRow)
var result = backend_proxy.delete_user(obj.id)
if(result.code !== 200)
{
alert.show(result.msg)
return
}
userModel.remove(userTableView.currentRow)
}
function update_user(obj)
{
var result = backend_proxy.update_user(JSON.stringify(obj))
if(result.code !== 200)
{
alert.show(result.msg)
return
}
}
Rectangle{
height: parent.height
anchors.left:parent.left
anchors.right: parent.right
anchors.leftMargin: 5
Rectangle{
anchors.left : parent.left
height: 40
anchors.top: parent.top
anchors.right: parent.right
border.width: 1
color: "#f3f3f3"
border.color: "lightgray"
Row
{
x: 5
anchors.verticalCenter: parent.verticalCenter
spacing: 5
QxTitleButton{
text: "添加"
onClicked: add_user()
}
QxTitleButton{
text: "删除"
enabled: userTableView.currentRow > -1
onClicked: {
var role = userModel.get(userTableView.currentRow).role
var name = userModel.get(userTableView.currentRow).name
if(name == g_session.name)
{
alert.show("当前用户不可删除")
return
}
removeUserDlg.msg = userModel.get(userTableView.currentRow).name
removeUserDlg.visible = true
}
}
}
}
TableView{
id: userTableView
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.topMargin: 40
// headerDelegate: Rectangle{
// anchors.top: parent.top
// width: parent.width
// height: 20
// color: "white"
// QxText {
// anchors.centerIn: parent
// font.pointSize: 10
// text: styleData.value
// }
// Rectangle{
// width: 1
// height: parent.height
// visible: styleData.value !== "序号"
// color: "lightgray"
// }
// Rectangle{
// y: parent.height
// width: parent.width
// height: 1
// color: "lightgray"
// }
// }
// rowDelegate: Rectangle{
// height: 25
// color : userTableView.currentRow === styleData.row ? "#beebff": ( (styleData.row %2 == 0) ? "#f2f2f2": "white" )
// }
// itemDelegate: Item {
// clip: true
// QxText {
// visible: styleData.role === "id"
// x: 5
// anchors.centerIn: parent
// color: "#999999"
// elide: styleData.elideMode
// font.pointSize: 10
// text: styleData.row + 1
// }
// QxText{
// z: 2
// visible: styleData.role == "name"&& !tp.visible
// text: !!model ? model.name : ""
// }
// QxText{
// z: 2
// visible: styleData.role == "password"&& !tp.visible
// text: !!model ? model.password : ""
// }
// Item{
// anchors.fill: parent
// visible: styleData.role == "role"
// QxText {
// text: !!model ? ( model.role == 0 ? "管理员" : "员工" ) : ""
// }
// MouseArea{
// anchors.fill: parent
// enabled: !!model ? ( model.name != g_session.name ) : false
// onClicked: {
// if(model.role == 1)
// model.role = 0
// else
// model.role = 1
// update_user(userModel.get(styleData.row))
// }
// }
// }
// QxTextInput{
// z: 2
// id: tp
// visible: false
// onTextChanged: {
// if( styleData.role === "name" )
// {
// if(text != styleData.value){
// model.name = text
// update_user(userModel.get(styleData.row))
// }
// }
// else if(styleData.role === "password")
// {
// if(text != styleData.value)
// {
// model.password = text
// update_user(userModel.get(styleData.row))
// }
// }
// }
// onFocusChanged: {
// if(!focus)
// visible = false
// }
// Connections{
// target: self
// function onShowDialog()
// {
// tp.visible = false
// }
// }
// }
// MouseArea{
// visible: styleData.role !== "role" && styleData.role !== "id"
// anchors.fill: parent
// onClicked: {
// tp.text = styleData.value
// tp.focus = true
// tp.visible = true
// }
// }
// Rectangle{
// width: 1
// height: parent.height
// visible: styleData.role !== "id"
// color: "lightgray"
// }
// }
Rectangle{
width: parent.width
height: 1
color: "lightgray"
}
// TableViewColumn {
// id: planNoCol
// title: "序号"
// role: "id"
// width: 80
// }
// TableViewColumn {
// id: usernameCol
// title: "用户名"
// role: "name"
// width: (userTableView.width - 82 ) /3
// }
// TableViewColumn {
// id: passwordCol
// title: "密码"
// role: "password"
// width: usernameCol.width
// }
// TableViewColumn {
// id: roleCol
// title: "权限"
// role: "role"
// width: usernameCol.width
// }
model: userModel
}
}
Dialog {
id: removeUserDlg
property var msg: ""
title: "删除用户"
standardButtons: Dialog.NoButton
Column
{
anchors.centerIn: parent
spacing: 10
QxText {
text: "删除用户:\n" + removeUserDlg.msg
}
Row
{
anchors.right: parent.right
spacing: 20
Button
{
text: "是"
//style: ButtonStyle{}
onClicked: removeUserDlg.accept()
}
Button
{
text: "否"
//style: ButtonStyle{}
onClicked: removeUserDlg.reject()
}
}
}
visible: false
width: 300
height: 100
onAccepted: delete_user()
}
}