Commit 1fdef2b9 by 温丽香

账户页面联调完成

1 parent 0165f96d
Pipeline #4299 passed
in 1 minute 55 seconds
...@@ -5,6 +5,11 @@ const FRONT = '/front' ...@@ -5,6 +5,11 @@ const FRONT = '/front'
const USER = '/user' const USER = '/user'
export const loginApi = data => axios(POST, FRONT + USER + '/login', data) export const loginApi = data => axios(POST, FRONT + USER + '/login', data)
export const logoutApi = data => axios(GET, FRONT + USER + '/logout', data)
export const getUsers = data => axios(GET, FRONT + USER + '/query_list', data)
export const createUser = data => axios(POST, FRONT + USER + '/add', data)
export const deleteUser = data => axios(GET, FRONT + USER + '/delete', data)
export const editUser = data => axios(POST, FRONT + USER + '/change', data)
const PARAMETER = '/parameter' const PARAMETER = '/parameter'
export const getParameter = data => axios(GET, FRONT + PARAMETER + '/query_list', data) export const getParameter = data => axios(GET, FRONT + PARAMETER + '/query_list', data)
......
...@@ -30,6 +30,9 @@ export default (method, url, data, config) => { ...@@ -30,6 +30,9 @@ export default (method, url, data, config) => {
} }
// 添加请求拦截器 // 添加请求拦截器
Axios.interceptors.request.use(function(config) { Axios.interceptors.request.use(function(config) {
for (const key in config.params) {
if (config.params[key] === '' || config.params[key] === undefined) delete config.params[key]
}
const urlBase = config.url.split('?')[0] const urlBase = config.url.split('?')[0]
const urlQueryArr = Array.from(new URLSearchParams(config.url.split('?')[1])) const urlQueryArr = Array.from(new URLSearchParams(config.url.split('?')[1]))
let result = '?' let result = '?'
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
<script lang="ts"> <script lang="ts">
import { Vue, Prop, Component, Watch } from 'vue-property-decorator' import { Vue, Prop, Component, Watch } from 'vue-property-decorator'
import { getUser, removeUser } from '@/utils/user' import { getUser, removeUser } from '@/utils/user'
import { logoutApi } from '@/axios'
import Dialog from '@/helpers/dialog' import Dialog from '@/helpers/dialog'
import seetaPopover from '@/components/seeta-ui/seeta-popover.vue' import seetaPopover from '@/components/seeta-ui/seeta-popover.vue'
...@@ -54,6 +55,7 @@ export default class userInfo extends Vue { ...@@ -54,6 +55,7 @@ export default class userInfo extends Vue {
async logout() { async logout() {
removeUser() removeUser()
const res = await logoutApi()
this.$router.replace({ name: 'login' }) this.$router.replace({ name: 'login' })
} }
......
...@@ -64,10 +64,11 @@ ...@@ -64,10 +64,11 @@
<st-form <st-form
label-width="90px" label-width="90px"
ref="form" ref="form"
:model="form"> :model="form"
:rules="rules">
<st-form-item <st-form-item
:label="'账号:'"> :label="'账号:'">
<st-input v-model="form.account"></st-input> <st-input v-model="form.username" :disabled="submitType === 'edit'"></st-input>
</st-form-item> </st-form-item>
<st-form-item <st-form-item
:label="'角色:'"> :label="'角色:'">
...@@ -77,13 +78,21 @@ ...@@ -77,13 +78,21 @@
:label="'邮箱:'"> :label="'邮箱:'">
<st-input v-model="form.email"></st-input> <st-input v-model="form.email"></st-input>
</st-form-item> </st-form-item>
<st-form-item <st-form-item v-if="submitType === 'create'"
:label="'初始密码:'"> :label="'初始密码:'">
<st-input v-model="form.password"></st-input> <st-input v-model="form.passwd" type="password"></st-input>
</st-form-item> </st-form-item>
<st-form-item <st-form-item v-if="submitType === 'create'"
:label="'重复密码:'"> :label="'重复密码:'">
<st-input v-model="form.confirmPwd"></st-input> <st-input v-model="form.confirmPwd" type="password"></st-input>
</st-form-item>
<st-form-item v-if="submitType === 'edit'"
:label="'原密码:'">
<st-input v-model="form.passwordd" type="password"></st-input>
</st-form-item>
<st-form-item v-if="submitType === 'edit'"
:label="'新密码:'">
<st-input v-model="form.new_passwordd" type="password"></st-input>
</st-form-item> </st-form-item>
</st-form> </st-form>
</div> </div>
...@@ -96,11 +105,21 @@ ...@@ -96,11 +105,21 @@
</template> </template>
<script> <script>
import { getUsers, createUser, deleteUser, editUser } from '@/axios'
import browserStorage from '@/services/local-storage' import browserStorage from '@/services/local-storage'
import { rTimeMin } from '@/utils/system.js' import { rTimeMin } from '@/utils/system.js'
import Dialog from '@/helpers/dialog' import Dialog from '@/helpers/dialog'
export default { export default {
data() { data() {
const validatePasswordConfirmation = (rule, value, callback) => {
if (value === '') {
callback(new Error('请确认密码'))
} else if (value !== this.form.passwd && value !== this.form.ConfirmPwd) {
callback(new Error('两次密码输入不一致'))
} else {
callback()
}
}
return { return {
// 查询字段 // 查询字段
userName: '', userName: '',
...@@ -113,27 +132,26 @@ export default { ...@@ -113,27 +132,26 @@ export default {
currentPage: 1, currentPage: 1,
currentSize: 10, currentSize: 10,
loadingStatus: false, loadingStatus: false,
borderColor: '#ccc',
definitions: [ definitions: [
{ {
label: '账号', label: '账号',
render: 'number' render: 'username'
}, },
{ {
label: '角色', label: '角色',
render: 'name' render: 'role'
}, },
{ {
label: '邮箱', label: '邮箱',
render: 'type' render: 'email'
}, },
{ {
label: '创建人', label: '创建人',
render: 'desc' render: 'creater'
}, },
{ {
label: '创建日期', label: '创建日期',
render: 'desc' render: 'create_date'
}, },
{ {
label: '备注', label: '备注',
...@@ -146,37 +164,22 @@ export default { ...@@ -146,37 +164,22 @@ export default {
slotName: 'operate' slotName: 'operate'
}, },
], ],
tokenList: [ tokenList: [],
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' }, total: 0,
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' }, rules: { // 表单校验
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' }, passwordConfirmation: [
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' }, { required: true, message: '请确认密码', trigger: 'blur' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' }, { validator: validatePasswordConfirmation, trigger: 'blur' }
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' }, ]
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' }, },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
{ number: 1, name: 'aa', type: 'aa', desc: 'aaaa' },
],
total: 20
} }
}, },
watch: { watch: {
'$route.query': { '$route.query': {
handler(val) { handler(val) {
if (!val) return if (JSON.stringify(val) === '{}') return
this.currentPage = Number(val.page_index) this.currentPage = Number(val.page_index) || 1
this.currentSize = Number(val.page_size) this.currentSize = Number(val.page_size) || 10
this.getData() this.getData()
}, },
immediate: true, immediate: true,
...@@ -187,8 +190,40 @@ export default { ...@@ -187,8 +190,40 @@ export default {
// this.getData() // this.getData()
}, },
methods: { methods: {
submit() { async submit() {
this.showDialog = false this.$refs.form.validate(async valid => {
if (valid) {
let res = ''
let submitForm = ''
switch (this.submitType) {
case 'create':
submitForm = JSON.parse(JSON.stringify(this.form))
delete submitForm.email
delete submitForm.confirmPwd
submitForm.creater = 'admin'
res = await createUser(submitForm)
if (res && res.data && res.data.code === 0) {
this.getData()
}
this.showDialog = false
break
case 'edit':
submitForm = JSON.parse(JSON.stringify(this.form))
delete submitForm.email
delete submitForm.confirmPwd
submitForm.creater = 'admin'
res = await editUser(submitForm)
if (res && res.data && res.data.code === 0) {
this.getData()
}
this.showDialog = false
break
default:
this.showDialog = false
break
}
}
})
}, },
cancelSubmit() { cancelSubmit() {
this.showDialog = false this.showDialog = false
...@@ -196,50 +231,31 @@ export default { ...@@ -196,50 +231,31 @@ export default {
handleCreate() { handleCreate() {
this.submitType = 'create' this.submitType = 'create'
this.showDialog = true this.showDialog = true
this.form = {}
}, },
handleEdit(row) { handleEdit(row) {
this.submitType = 'edit' this.submitType = 'edit'
this.showDialog = true this.showDialog = true
this.form = JSON.parse(JSON.stringify(row))
}, },
async handleDelete(row) { async handleDelete(row) {
console.log(row)
const confirmDelete = await Dialog.confirm('提示', { message: '是否删除此账号?' }) const confirmDelete = await Dialog.confirm('提示', { message: '是否删除此账号?' })
if (!confirmDelete) return if (!confirmDelete) return
const res = await this.getData() const res = await deleteUser({ username: row.username })
if (res) { if (res) {
Toast.success('操作成功') Toast.success('操作成功')
this.getData() this.getData()
} }
}, },
checkSearchContent() {
if (this.deviceName && this.deviceName.search(this.formatSearchName) !== -1) {
this.borderColor = '#f00'
return true
}
this.borderColor = '#ccc'
return false
},
async getData() { async getData() {
// if (this.checkSearchContent()) return this.loadingStatus = true
// let startTime = '' const res = await getUsers({ pages: this.currentPage - 1, pagesize: this.currentSize })
// let endTime = '' if (res && res.data && res.data.code === 0) {
// if (this.timeSection && this.timeSection.length) { this.tokenList = res.data.data.users
// startTime = new Date(+this.timeSection[0] + 8 * 3600 * 1000).toISOString() this.total = res.data.data.total
// endTime = new Date(+this.timeSection[1] + 32 * 3600 * 1000).toISOString() }
// } this.loadingStatus = false
// this.loadingStatus = true
// const res = await projectsApi.getProjectDeviceLogs(
// browserStorage.getItem('projectId'), this.deviceName,
// endTime,
// this.logLevel, this.currentPage, this.currentSize,
// startTime
// )
// if (res && res.data) {
// this.tokenList = res.data.data
// this.total = res.data.total
// }
// this.loadingStatus = false
} }
}, },
} }
......
...@@ -107,16 +107,30 @@ export default { ...@@ -107,16 +107,30 @@ export default {
}, },
], ],
tokenList: [], tokenList: [],
total: 0 total: 0,
currentPage: 1,
currentSize: 10
}
},
watch: {
'$route.query': {
handler(val) {
if (JSON.stringify(val) === '{}') return
this.currentPage = Number(val.page_index) || 1
this.currentSize = Number(val.page_size) || 10
this.getData()
},
immediate: true,
deep: true
} }
}, },
mounted() { mounted() {
this.getData() // this.getData()
}, },
methods: { methods: {
async getData() { async getData() {
this.loadingStatus = true this.loadingStatus = true
const res = await getApp({ pages: 0, pagesize: 10 }) const res = await getApp({ pages: this.currentPage - 1, pagesize: this.currentSize })
if (res && res.data && res.data.code === 0) { if (res && res.data && res.data.code === 0) {
this.tokenList = res.data.data.apps this.tokenList = res.data.data.apps
this.total = res.data.data.total this.total = res.data.data.total
......
...@@ -114,8 +114,8 @@ export default { ...@@ -114,8 +114,8 @@ export default {
watch: { watch: {
'$route.query': { '$route.query': {
handler(val) { handler(val) {
if (!val) return if (JSON.stringify(val) === '{}') return
this.currentPage = Number(val.page_index) this.currentPage = Number(val.page_index) || 1
this.currentSize = Number(val.page_size) || 10 this.currentSize = Number(val.page_size) || 10
this.getData() this.getData()
}, },
......
...@@ -142,7 +142,7 @@ export default { ...@@ -142,7 +142,7 @@ export default {
}, },
async getTwoData() { async getTwoData() {
this.loadingTwo = true this.loadingTwo = true
const twoLevel = await getParameter({ parent: this.parentLevel, pages: this.twoCurrentPage - 1, pagesize: 10 }) const twoLevel = await getParameter({ parent: this.parentLevel === '' ? 0 : this.parentLevel, pages: this.twoCurrentPage - 1, pagesize: 10 })
if (twoLevel && twoLevel.data && twoLevel.data.code === 0) { if (twoLevel && twoLevel.data && twoLevel.data.code === 0) {
this.twoList = twoLevel.data.parameters.datas.map((item, index) => { this.twoList = twoLevel.data.parameters.datas.map((item, index) => {
item.order = index + 1 + (this.twoCurrentPage - 1) * 10 item.order = index + 1 + (this.twoCurrentPage - 1) * 10
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!