使用Vue, html, ElementUI搭建一个租户管理页面
时间: 2024-06-08 09:09:12 浏览: 165
thinkphp6_vue+elementUi后台基础管理框架.zip
好的,下面是一个简单的租户管理页面的示例代码:
```
<template>
<div>
<el-row :gutter="20">
<el-col :span="12">
<el-input v-model="searchText" placeholder="搜索租户"></el-input>
</el-col>
<el-col :span="12" style="text-align: right">
<el-button type="primary" @click="addTenant">添加租户</el-button>
</el-col>
</el-row>
<el-table :data="tenantList" style="width: 100%" stripe>
<el-table-column prop="name" label="租户名称"></el-table-column>
<el-table-column prop="email" label="联系邮箱"></el-table-column>
<el-table-column prop="phone" label="联系电话"></el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="text" @click="editTenant(scope.row)">编辑</el-button>
<el-button type="text" @click="deleteTenant(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-dialog :visible.sync="dialogVisible" title="添加/编辑租户">
<el-form :model="tenantForm" :rules="rules" ref="tenantForm" label-width="80px">
<el-form-item label="租户名称" prop="name">
<el-input v-model="tenantForm.name"></el-input>
</el-form-item>
<el-form-item label="联系邮箱" prop="email">
<el-input v-model="tenantForm.email"></el-input>
</el-form-item>
<el-form-item label="联系电话" prop="phone">
<el-input v-model="tenantForm.phone"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="saveTenant">确 定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
export default {
data() {
return {
searchText: '',
tenantList: [
{ name: '租户1', email: 'tenant1@example.com', phone: '123456789' },
{ name: '租户2', email: 'tenant2@example.com', phone: '987654321' },
],
dialogVisible: false,
tenantForm: {
name: '',
email: '',
phone: '',
},
rules: {
name: [{ required: true, message: '请输入租户名称', trigger: 'blur' }],
email: [{ required: true, message: '请输入联系邮箱', trigger: 'blur' }],
phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
},
}
},
methods: {
addTenant() {
this.tenantForm = { name: '', email: '', phone: '' }
this.dialogVisible = true
},
editTenant(row) {
this.tenantForm = { ...row }
this.dialogVisible = true
},
saveTenant() {
this.$refs.tenantForm.validate(valid => {
if (valid) {
const index = this.tenantList.findIndex(
item => item.name === this.tenantForm.name
)
if (index >= 0) {
this.tenantList.splice(index, 1, { ...this.tenantForm })
} else {
this.tenantList.push({ ...this.tenantForm })
}
this.dialogVisible = false
}
})
},
deleteTenant(row) {
const index = this.tenantList.findIndex(
item => item.name === row.name
)
if (index >= 0) {
this.tenantList.splice(index, 1)
}
},
},
computed: {
filteredTenantList() {
return this.tenantList.filter(item =>
item.name.toLowerCase().includes(this.searchText.toLowerCase())
)
},
},
}
</script>
```
这个页面使用了 ElementUI 的组件来实现输入框、表格、对话框等功能。在 Vue 的 data 中,定义了 searchText(搜索文本)、tenantList(租户列表)、dialogVisible(对话框是否显示)和 tenantForm(租户表单数据)等变量。methods 中定义了一些方法,例如 addTenant(添加租户)、editTenant(编辑租户)、deleteTenant(删除租户)和 saveTenant(保存租户)等。在 computed 中,使用 searchText 过滤出符合条件的租户列表。
阅读全文