环境变量配置
# 开发环境接口配置 /.env.development
ENV = 'production'
VUE_APP_BASE_URL = 'https://duanju.xun-hu.net'
# 测试环境接口配置 /.env.test
ENV = 'test'
VUE_APP_BASE_URL = 'https://duanju.xun-hu.net'
# 正式环境接口配置 /.env.production
ENV = 'production'
VUE_APP_BASE_URL = 'https://duanju.xun-hu.net'
# 打包时区分不同环境打包
npm run build:dev // 开发环境
npm run build:test // 测试环境
npm run build // 正式环境
可以根据业务需求,新增环境变量
使用:process.env.VUE_APP_BASE_URL
请求
# /utils/request.js
# 您可以根据实际的业务需求修改请求拦截器和响应拦截器
// 请求拦截器
service.interceptors.request.use(
config => {
config.header.key = 'abcd' // 自定义请求头,比如新增加密参数
return config
}
)
// 响应拦截器
service.interceptors.response.use(
response => {
// 处理响应的业务逻辑
return response.data
},
err => {
// 处理响应的业务逻辑
}
)
ui组件
项目ui库使用的element-ui 2.15.12
基于element-ui二次开发的组件 /src/components/ui 您可以自己修改或增加
最佳实践
<template>
<ai-list class="list">
<ai-title
slot="title"
title="账号管理"
:isShowBottomBorder="true">
</ai-title>
<template slot="content">
<ai-search-bar>
<template #left>
<el-button type="primary" size="medium" icon="iconfont iconAdd" @click="isShow = true">添加</el-button>
</template>
<template #right>
<el-input
v-model="search.search_value"
class="search-input"
size="medium"
v-throttle="() => {search.current = 1, getList()}"
placeholder="请输入用户名"
clearable
@clear="search.current = 1, search.search_value = '', getList()"
suffix-icon="iconfont iconSearch">
</el-input>
</template>
</ai-search-bar>
<ai-table
:tableData="tableData"
:col-configs="colConfigs"
:total="total"
style="margin-top: 8px;"
:current.sync="search.current"
:size.sync="search.size"
v-loading="isLoading"
@getList="getList">
<el-table-column slot="status" width="140px" label="状态" align="center">
<template slot-scope="{ row }">
<el-switch
v-model="row.is_disable"
:active-value="0"
:inactive-value="1"
@change="e => onChange(row.two_member_id, e)">
</el-switch>
</template>
</el-table-column>
<el-table-column width="160px" fixed="right" label="操作" align="center">
<template slot-scope="{ row }">
<div class="table-options">
<el-button type="text" @click="edit(row)">编辑</el-button>
<el-button type="text" @click="toStatistics(row.two_member_id)">数据统计</el-button>
<el-button type="text" @click="remove(row)">删除</el-button>
</div>
</template>
</el-table-column>
</ai-table>
<ai-dialog
:title="id ? '编辑子账号' : '添加子账号'"
width="790px"
:visible.sync="isShow"
customFooter
@close="onClose">
<el-form class="ai-form" :model="form" ref="form" label-width="80px">
<el-form-item label="用户名" style="width: 100%;" prop="username" :rules="[{ required: true, message: '请输入用户名', trigger: 'blur' }]">
<el-input size="medium" placeholder="请输入用户名" v-model="form.username"></el-input>
</el-form-item>
<el-form-item label="昵称" style="width: 100%;" prop="nickname" :rules="[{ required: true, message: '请输入昵称', trigger: 'blur' }]">
<el-input size="medium" placeholder="请输入昵称" v-model="form.nickname"></el-input>
</el-form-item>
<el-form-item label="密码" style="width: 100%;" prop="password" :rules="[{ required: id ? false : true, message: '请输入密码', trigger: 'blur' }]">
<el-input size="medium" type="password" placeholder="请输入密码" v-model="form.password"></el-input>
</el-form-item>
<el-form-item label="手机号" style="width: 100%;" prop="phone">
<el-input size="medium" placeholder="请输入手机号" v-model="form.phone"></el-input>
</el-form-item>
</el-form>
<div class="dialog-footer" slot="footer">
<el-button @click="isShow = false">取消</el-button>
<el-button @click="onConfirm" type="primary" :loading="btnLoading">确定</el-button>
</div>
</ai-dialog>
</template>
</ai-list>
</template>
<script>
export default {
name: 'SubAccount',
data () {
return {
search: {
page: 1,
limit: 10,
search_field: 'username',
search_exp: 'like',
search_value: ''
},
form: {
username: '',
nickname: '',
phone: '',
password: ''
},
isLoading: false,
isShow: false,
colConfigs: [
{ prop: 'username', label: '名称' },
{ prop: 'nickname', label: '昵称', align: 'center' },
{ prop: 'phone', label: '手机号', align: 'center' },
{ prop: 'create_time', label: '注册时间', align: 'center' },
{ slot: 'status', align: 'center' }
],
btnLoading: false,
id: '',
tableData: [],
total: 0
}
},
created () {
this.getList()
},
methods: {
getList () {
this.isLoading = true
this.$http.post(`/api/member.MemberTwo/list`, null, {
params: {
...this.search
}
}).then(res => {
if (res.code == 200) {
this.tableData = res.data.list
this.total = res.data.count
}
this.isLoading = false
}).catch(() => {
this.isLoading = false
})
},
toStatistics (memberId) {
this.$router.push(`/account/subAccountDetail?memberId=${memberId}`)
},
edit (e) {
this.id = e.two_member_id
this.form = {
...e
}
this.isShow = true
},
onClose () {
this.id = ''
this.form.nickname = ''
this.form.username = ''
this.form.phone = ''
this.form.password = ''
},
onConfirm () {
const api = this.id ? `/api/member.MemberTwo/edit` : '/api/member.MemberTwo/add'
this.$refs.form.validate((valid) => {
if (valid) {
this.btnLoading = true
this.$http.post(api, {
...this.form,
two_member_id: this.id || ''
}).then(res => {
if (res.code === 200) {
this.isShow = false
this.$message.success(this.id ? '修改成功' : '添加成功')
this.getList()
this.id = ''
}
this.btnLoading = false
}).catch(() => {
this.btnLoading = false
})
}
})
},
remove (e) {
this.$confirm('确定删除该数据?').then(() => {
this.$http.post(`/api/member.MemberTwo/dele`, {
ids: [e.two_member_id]
}).then(res => {
if (res.code == 200) {
this.$message.success('删除成功!')
this.getList()
}
})
})
},
onChange (userId, e) {
this.$http.post(`/api/member.MemberTwo/disable`, {
ids: [userId],
is_disable: e
}).then(res => {
if (res.code == 200) {
this.$message.success('操作成功!')
this.getList()
}
})
}
}
}
</script>
<style scoped lang="scss">
</style>