Initial commit
This commit is contained in:
516
ruoyi-ui/src/views/monitor/account/index.vue
Normal file
516
ruoyi-ui/src/views/monitor/account/index.vue
Normal file
@@ -0,0 +1,516 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
|
||||
<el-form-item label="账号名称" prop="accountName">
|
||||
<el-input
|
||||
v-model="queryParams.accountName"
|
||||
placeholder="请输入账号名称"
|
||||
clearable
|
||||
size="small"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input
|
||||
v-model="queryParams.username"
|
||||
placeholder="请输入用户名"
|
||||
clearable
|
||||
size="small"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="账号状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="账号状态" clearable size="small">
|
||||
<el-option
|
||||
v-for="dict in statusOptions"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictLabel"
|
||||
:value="dict.dictValue"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
icon="el-icon-plus"
|
||||
size="mini"
|
||||
@click="handleAdd"
|
||||
v-hasPermi="['monitor:account:add']"
|
||||
>新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="success"
|
||||
icon="el-icon-edit"
|
||||
size="mini"
|
||||
:disabled="single"
|
||||
@click="handleUpdate"
|
||||
v-hasPermi="['monitor:account:edit']"
|
||||
>修改</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
icon="el-icon-delete"
|
||||
size="mini"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
v-hasPermi="['monitor:account:remove']"
|
||||
>删除</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="warning"
|
||||
icon="el-icon-download"
|
||||
size="mini"
|
||||
@click="handleExport"
|
||||
v-hasPermi="['monitor:account:export']"
|
||||
>导出</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="accountList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="ID" align="center" prop="id" width="80" />
|
||||
<el-table-column label="账号名称" align="center" prop="accountName" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="用户名" align="center" prop="username" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="状态" align="center" prop="status">
|
||||
<template slot-scope="scope">
|
||||
<dict-tag :options="statusOptions" :value="scope.row.status" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="过期时间" align="center" prop="expireTime" width="180">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.expireTime }}</span>
|
||||
<el-tag v-if="isExpired(scope.row)" type="danger" size="mini">已过期</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180" />
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-edit"
|
||||
@click="handleUpdate(scope.row)"
|
||||
v-hasPermi="['monitor:account:edit']"
|
||||
>修改</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope.row)"
|
||||
v-hasPermi="['monitor:account:remove']"
|
||||
>删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
:page.sync="queryParams.pageNum"
|
||||
:limit.sync="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
||||
<!-- 添加或修改对话框 -->
|
||||
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="账号名称" prop="accountName">
|
||||
<el-input v-model="form.accountName" placeholder="请输入账号名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input v-model="form.username" placeholder="请输入用户名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password" v-if="!form.id">
|
||||
<el-input v-model="form.password" type="password" placeholder="请输入密码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="账号状态">
|
||||
<el-radio-group v-model="form.status">
|
||||
<el-radio
|
||||
v-for="dict in statusOptions"
|
||||
:key="dict.dictValue"
|
||||
:label="dict.dictValue"
|
||||
>{{dict.dictLabel}}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="过期时间">
|
||||
<el-date-picker
|
||||
v-model="form.expireTime"
|
||||
type="datetime"
|
||||
placeholder="选择过期时间"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
style="width: 100%;"
|
||||
></el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item label="功能权限" prop="permissions">
|
||||
<div class="permission-config">
|
||||
<el-checkbox-group v-model="selectedPermissions" @change="onPermissionChange">
|
||||
<el-checkbox label="rakuten">日本乐天平台</el-checkbox>
|
||||
<el-checkbox label="amazon">亚马逊平台</el-checkbox>
|
||||
<el-checkbox label="zebra">斑马平台</el-checkbox>
|
||||
<el-checkbox label="shopee">虾皮购物平台</el-checkbox>
|
||||
<el-checkbox label="toolbox">工具箱功能</el-checkbox>
|
||||
<el-checkbox label="dataCollection">数据采集功能</el-checkbox>
|
||||
<el-checkbox label="priceCompare">1688比价功能</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" placeholder="请输入备注"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 注册对话框 -->
|
||||
<el-dialog title="客户端账号注册" :visible.sync="registerOpen" width="400px" append-to-body>
|
||||
<el-form ref="registerForm" :model="registerForm" :rules="registerRules" label-width="80px">
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input v-model="registerForm.username" placeholder="请输入用户名" @blur="checkUsername" />
|
||||
<span v-if="usernameChecking" class="checking">检查中...</span>
|
||||
<span v-else-if="usernameAvailable === false" class="error">用户名已存在</span>
|
||||
<span v-else-if="usernameAvailable === true" class="success">用户名可用</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password">
|
||||
<el-input v-model="registerForm.password" type="password" placeholder="请输入密码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="确认密码" prop="confirmPassword">
|
||||
<el-input v-model="registerForm.confirmPassword" type="password" placeholder="请再次输入密码" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitRegister" :loading="registerLoading">注 册</el-button>
|
||||
<el-button @click="cancelRegister">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listAccount, getAccount, delAccount, addAccount, updateAccount, registerAccount, checkUsername } from "@/api/monitor/account";
|
||||
|
||||
export default {
|
||||
name: "Account",
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 选中数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 总条数
|
||||
total: 0,
|
||||
// 账号表格数据
|
||||
accountList: [],
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
// 选中的权限列表
|
||||
selectedPermissions: [],
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
// 注册对话框
|
||||
registerOpen: false,
|
||||
registerLoading: false,
|
||||
usernameChecking: false,
|
||||
usernameAvailable: null,
|
||||
// 状态数据字典
|
||||
statusOptions: [
|
||||
{ dictLabel: "正常", dictValue: "0" },
|
||||
{ dictLabel: "停用", dictValue: "1" }
|
||||
],
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
accountName: null,
|
||||
username: null,
|
||||
status: null
|
||||
},
|
||||
// 表单参数
|
||||
form: {},
|
||||
// 注册表单
|
||||
registerForm: {
|
||||
username: null,
|
||||
password: null,
|
||||
confirmPassword: null
|
||||
},
|
||||
// 表单校验
|
||||
rules: {
|
||||
accountName: [
|
||||
{ required: true, message: "账号名称不能为空", trigger: "blur" }
|
||||
],
|
||||
username: [
|
||||
{ required: true, message: "用户名不能为空", trigger: "blur" }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: "密码不能为空", trigger: "blur" },
|
||||
{ min: 6, message: "密码长度不能少于6位", trigger: "blur" }
|
||||
]
|
||||
},
|
||||
// 注册表单校验
|
||||
registerRules: {
|
||||
username: [
|
||||
{ required: true, message: "用户名不能为空", trigger: "blur" }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: "密码不能为空", trigger: "blur" },
|
||||
{ min: 6, message: "密码长度不能少于6位", trigger: "blur" }
|
||||
],
|
||||
confirmPassword: [
|
||||
{ required: true, message: "确认密码不能为空", trigger: "blur" },
|
||||
{ validator: this.validateConfirmPassword, trigger: "blur" }
|
||||
]
|
||||
}
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.getList();
|
||||
},
|
||||
methods: {
|
||||
/** 查询账号列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listAccount(this.queryParams).then(response => {
|
||||
this.accountList = response.rows;
|
||||
this.total = response.total;
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
// 检查是否过期
|
||||
isExpired(row) {
|
||||
if (!row.expireTime) return false;
|
||||
return new Date(row.expireTime) < new Date();
|
||||
},
|
||||
// 表单重置
|
||||
reset() {
|
||||
this.form = {
|
||||
id: null,
|
||||
accountName: null,
|
||||
username: null,
|
||||
password: null,
|
||||
status: "0",
|
||||
expireTime: null,
|
||||
remark: null,
|
||||
permissions: null
|
||||
};
|
||||
this.resetForm("form");
|
||||
this.selectedPermissions = [];
|
||||
},
|
||||
// 搜索按钮操作
|
||||
handleQuery() {
|
||||
this.queryParams.pageNum = 1;
|
||||
this.getList();
|
||||
},
|
||||
// 重置按钮操作
|
||||
resetQuery() {
|
||||
this.resetForm("queryForm");
|
||||
this.handleQuery();
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map(item => item.id)
|
||||
this.single = selection.length!==1
|
||||
this.multiple = !selection.length
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset();
|
||||
this.open = true;
|
||||
this.title = "添加客户端账号";
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
const id = row.id || this.ids[0]
|
||||
getAccount(id).then(response => {
|
||||
this.form = response.data;
|
||||
this.selectedPermissions = this.parsePermissions(this.form.permissions);
|
||||
this.open = true;
|
||||
this.title = "修改客户端账号";
|
||||
});
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm() {
|
||||
this.$refs["form"].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.id != null) {
|
||||
updateAccount(this.form).then(response => {
|
||||
this.$modal.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
} else {
|
||||
addAccount(this.form).then(response => {
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const ids = row.id || this.ids;
|
||||
this.$modal.confirm('是否确认删除账号编号为"' + ids + '"的数据项?').then(function() {
|
||||
return delAccount(ids);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.$modal.msgSuccess("删除成功");
|
||||
}).catch(() => {});
|
||||
},
|
||||
/** 导出按钮操作 */
|
||||
handleExport() {
|
||||
this.download('monitor/account/export', {
|
||||
...this.queryParams
|
||||
}, `客户端账号_${new Date().getTime()}.xlsx`)
|
||||
},
|
||||
/** 取消按钮 */
|
||||
cancel() {
|
||||
this.open = false;
|
||||
this.reset();
|
||||
},
|
||||
/** 权限配置变化 */
|
||||
onPermissionChange(value) {
|
||||
const permissions = {};
|
||||
value.forEach(permission => {
|
||||
permissions[permission] = true;
|
||||
});
|
||||
this.form.permissions = JSON.stringify(permissions);
|
||||
},
|
||||
/** 解析权限配置 */
|
||||
parsePermissions(permissionsJson) {
|
||||
if (!permissionsJson) {
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
const permissions = JSON.parse(permissionsJson);
|
||||
return Object.keys(permissions).filter(key => permissions[key] === true);
|
||||
} catch (e) {
|
||||
console.error('解析权限配置失败:', e);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
/** 打开注册对话框 */
|
||||
handleRegister() {
|
||||
this.resetRegisterForm();
|
||||
this.registerOpen = true;
|
||||
},
|
||||
/** 重置注册表单 */
|
||||
resetRegisterForm() {
|
||||
this.registerForm = {
|
||||
username: null,
|
||||
password: null,
|
||||
confirmPassword: null
|
||||
};
|
||||
this.resetForm("registerForm");
|
||||
this.usernameAvailable = null;
|
||||
},
|
||||
/** 检查用户名是否可用 */
|
||||
async checkUsername() {
|
||||
if (!this.registerForm.username) return;
|
||||
|
||||
this.usernameChecking = true;
|
||||
try {
|
||||
const response = await checkUsername(this.registerForm.username);
|
||||
this.usernameAvailable = response.data;
|
||||
} catch (error) {
|
||||
this.usernameAvailable = false;
|
||||
}
|
||||
this.usernameChecking = false;
|
||||
},
|
||||
/** 确认密码校验 */
|
||||
validateConfirmPassword(rule, value, callback) {
|
||||
if (value !== this.registerForm.password) {
|
||||
callback(new Error('两次输入密码不一致'));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
/** 提交注册 */
|
||||
submitRegister() {
|
||||
this.$refs["registerForm"].validate(valid => {
|
||||
if (valid && this.usernameAvailable === true) {
|
||||
this.registerLoading = true;
|
||||
const data = {
|
||||
accountName: this.registerForm.username, // 使用用户名作为账号名称
|
||||
username: this.registerForm.username,
|
||||
password: this.registerForm.password,
|
||||
status: "0"
|
||||
};
|
||||
registerAccount(data).then(response => {
|
||||
this.$modal.msgSuccess("注册成功");
|
||||
this.registerOpen = false;
|
||||
this.getList();
|
||||
}).finally(() => {
|
||||
this.registerLoading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 取消注册 */
|
||||
cancelRegister() {
|
||||
this.registerOpen = false;
|
||||
this.resetRegisterForm();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.permission-config {
|
||||
padding: 10px;
|
||||
border: 1px solid #e6e6e6;
|
||||
border-radius: 4px;
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
.permission-config .el-checkbox {
|
||||
display: block;
|
||||
margin: 8px 0;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.permission-config .el-checkbox-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.permission-config .el-checkbox + .el-checkbox {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.checking {
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #f56c6c;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.success {
|
||||
color: #67c23a;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user