mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-21 02:20:54 +08:00
exam-user
This commit is contained in:
@@ -35,6 +35,9 @@
|
||||
<el-menu-item-group>
|
||||
<el-menu-item index="/exam"><i class="el-icon-menu" />Exam</el-menu-item>
|
||||
</el-menu-item-group>
|
||||
<el-menu-item-group>
|
||||
<el-menu-item index="/exam-user"><i class="el-icon-menu" />Exam user</el-menu-item>
|
||||
</el-menu-item-group>
|
||||
</el-submenu>
|
||||
</el-menu>
|
||||
</el-aside>
|
||||
@@ -76,6 +79,7 @@ export default {
|
||||
}
|
||||
})
|
||||
router.beforeEach((to, from, next) => {
|
||||
console.log("App beforeEach to", to)
|
||||
if (to.path == '/login') {
|
||||
// 如果路径是 /login 则正常执行
|
||||
next()
|
||||
|
||||
@@ -29,26 +29,32 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { onMounted, reactive, toRefs } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import axios from '../utils/axios'
|
||||
import {computed, onMounted, reactive, toRefs, watch} from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { localRemove, pathMap } from '../utils'
|
||||
import api from "../utils/api";
|
||||
|
||||
export default {
|
||||
name: 'Header',
|
||||
setup() {
|
||||
setup(props, context) {
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const state = reactive({
|
||||
name: 'dashboard',
|
||||
userInfo: null,
|
||||
hasBack: false
|
||||
})
|
||||
onMounted(() => {
|
||||
const pathname = window.location.hash.split('/')[1] || ''
|
||||
console.log("pathname: ", pathname)
|
||||
getUserInfo()
|
||||
console.log("Head onMounted!")
|
||||
// console.log(props, context)
|
||||
})
|
||||
watch(
|
||||
() => route,
|
||||
(newValue, oldValue) => {
|
||||
console.log(newValue, 'new')
|
||||
console.log(oldValue, 'old')
|
||||
}
|
||||
)
|
||||
const getUserInfo = async () => {
|
||||
const userInfo = await api.getUserBase()
|
||||
console.log(userInfo)
|
||||
@@ -64,7 +70,7 @@ export default {
|
||||
router.back()
|
||||
}
|
||||
router.afterEach((to) => {
|
||||
console.log('to', to)
|
||||
console.log("Head afterEach to", to)
|
||||
const { id } = to.query
|
||||
state.name = pathMap[to.name]
|
||||
if (id && to.name == 'add') {
|
||||
|
||||
Vendored
+1
@@ -3,4 +3,5 @@ import App from './App.vue'
|
||||
import ElementPlus from 'element-plus'
|
||||
import router from './router/index'
|
||||
import 'element-plus/lib/theme-chalk/index.css'
|
||||
// import './styles/common.scss'
|
||||
createApp(App).use(ElementPlus).use(router).mount('#app')
|
||||
|
||||
Vendored
+5
@@ -33,6 +33,11 @@ const router = createRouter({
|
||||
name: 'exam-form',
|
||||
component: () => import('../views/exam/form.vue')
|
||||
},
|
||||
{
|
||||
path: '/exam-user',
|
||||
name: 'exam-user',
|
||||
component: () => import('../views/exam/user.vue')
|
||||
},
|
||||
{
|
||||
path: '/agent-allow',
|
||||
name: 'agent-allow',
|
||||
|
||||
Vendored
Vendored
+3
@@ -54,6 +54,9 @@ const api = {
|
||||
listClass: (params = {}) => {
|
||||
return axios.get('class', {params: params});
|
||||
},
|
||||
listExamUser: (params = {}) => {
|
||||
return axios.get('exam-users', {params: params});
|
||||
},
|
||||
}
|
||||
|
||||
export default api
|
||||
|
||||
Vendored
-2
@@ -11,7 +11,6 @@ axios.defaults.headers['Authorization'] = 'Bearer ' + localGet('token')
|
||||
|
||||
// 请求拦截器,内部根据返回值,重新组装,统一管理。
|
||||
axios.interceptors.response.use(res => {
|
||||
console.log(res)
|
||||
if (typeof res.data !== 'object') {
|
||||
ElMessage.error('Server Error 1')
|
||||
return Promise.reject(res)
|
||||
@@ -22,7 +21,6 @@ axios.interceptors.response.use(res => {
|
||||
}
|
||||
return res.data
|
||||
}, error => {
|
||||
console.log(error.response)
|
||||
ElMessage.error(error.response.data.msg || 'Server Error 2')
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
Vendored
+2
-6
@@ -21,13 +21,8 @@ export function hasEmoji (str = '') {
|
||||
return str.match(reg) && str.match(reg).length
|
||||
}
|
||||
|
||||
// 单张图片上传
|
||||
export const uploadImgServer = 'http://backend-api-02.newbee.ltd/manage-api/v1/upload/file'
|
||||
// 多张图片上传
|
||||
export const uploadImgsServer = 'http://backend-api-02.newbee.ltd/manage-api/v1/upload/files'
|
||||
|
||||
export const pathMap = {
|
||||
login: '登录',
|
||||
login: 'Login',
|
||||
introduce: '系统介绍',
|
||||
dashboard: 'Dashboard',
|
||||
add: '添加商品',
|
||||
@@ -49,4 +44,5 @@ export const pathMap = {
|
||||
'user-form': 'User form',
|
||||
'exam': 'Exam',
|
||||
'exam-form': 'Exam form',
|
||||
'exam-user': 'Exam user',
|
||||
}
|
||||
|
||||
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
import {ref, reactive} from 'vue'
|
||||
|
||||
const useTable = () => {
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
query: {
|
||||
page: 1,
|
||||
sort_field: 'id',
|
||||
sort_type: 'desc'
|
||||
},
|
||||
tableData: [],
|
||||
multipleSelection: [],
|
||||
total: 0,
|
||||
currentPage: 1,
|
||||
perPage: 10
|
||||
})
|
||||
return state
|
||||
}
|
||||
|
||||
const renderTableData = (res, state) => {
|
||||
state.tableData = res.data.data
|
||||
state.page = res.data.meta.current_page
|
||||
state.total = res.data.meta.total
|
||||
state.currentPage = res.data.meta.current_page
|
||||
state.perPage = res.data.meta.per_page
|
||||
}
|
||||
|
||||
const resetTableSort = (val, state) => {
|
||||
console.log('resetTableSort', val)
|
||||
state.query.page = 1
|
||||
state.query.sort_field = val.prop
|
||||
state.query.sort_type = val.order
|
||||
}
|
||||
|
||||
export {
|
||||
useTable,
|
||||
renderTableData,
|
||||
resetTableSort
|
||||
}
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
<el-form-item label="Status" prop="status">
|
||||
<el-radio-group v-model="formData.status">
|
||||
<el-radio label="0">Enabled</el-radio>
|
||||
<el-radio label="1">Disabled</el-radio>
|
||||
<el-radio :label="0">Enabled</el-radio>
|
||||
<el-radio :label="1">Disabled</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
@@ -121,12 +121,19 @@ export default {
|
||||
],
|
||||
},
|
||||
})
|
||||
onMounted(() => {
|
||||
onMounted( () => {
|
||||
listAllClass()
|
||||
listAllIndex()
|
||||
if (id) {
|
||||
let res = api.getExam(id)
|
||||
// state.formData = res.data
|
||||
api.getExam(id).then(res => {
|
||||
state.formData.name = res.data.name
|
||||
state.formData.description = res.data.description
|
||||
state.formData.begin = res.data.begin
|
||||
state.formData.end = res.data.end
|
||||
state.formData.indexes = res.data.indexes
|
||||
state.formData.filters = res.data.filters
|
||||
state.formData.status = res.data.status
|
||||
})
|
||||
} else {
|
||||
let res = api.listExamIndex()
|
||||
state.formData.indexes = res.data
|
||||
@@ -146,8 +153,12 @@ export default {
|
||||
params.end = dayjs(params.end).format('YYYY-MM-DD HH:mm:ss')
|
||||
}
|
||||
console.log(params)
|
||||
let res = await api.storeExam(params)
|
||||
console.log(res)
|
||||
if (id) {
|
||||
await api.updateExam(id, params)
|
||||
} else {
|
||||
await api.storeExam(params)
|
||||
}
|
||||
await router.push({name: 'exam'})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<el-card class="swiper-container">
|
||||
<el-card class="">
|
||||
<template #header>
|
||||
<div class="header">
|
||||
<el-button type="primary" size="small" icon="el-icon-plus" @click="handleAdd">Add</el-button>
|
||||
@@ -10,7 +10,6 @@
|
||||
ref="multipleTable"
|
||||
:data="tableData"
|
||||
tooltip-effect="dark"
|
||||
style="width: 100%"
|
||||
@selection-change="handleSelectionChange">
|
||||
<el-table-column
|
||||
type="selection"
|
||||
@@ -66,8 +65,14 @@
|
||||
>
|
||||
<template #default="scope">
|
||||
<a style="cursor: pointer; margin-right: 10px" @click="handleEdit(scope.row.id)">Edit</a>
|
||||
<a style="cursor: pointer; margin-right: 10px" v-if="scope.row.goodsSellStatus == 0" @click="handleStatus(scope.row.goodsId, 1)">下架</a>
|
||||
<a style="cursor: pointer; margin-right: 10px" v-else @click="handleStatus(scope.row.goodsId, 0)">上架</a>
|
||||
<el-popconfirm
|
||||
title="Confirm Delete ?"
|
||||
@confirm="handleDelete(scope.row.id)"
|
||||
>
|
||||
<template #reference>
|
||||
<a style="cursor: pointer">Delete</a>
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -76,7 +81,7 @@
|
||||
background
|
||||
layout="prev, pager, next"
|
||||
:total="total"
|
||||
:page-size="pageSize"
|
||||
:page-size="perPage"
|
||||
:current-page="currentPage"
|
||||
@current-change="changePage"
|
||||
/>
|
||||
@@ -88,24 +93,29 @@ import { onMounted, reactive, ref, toRefs } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useRouter } from 'vue-router'
|
||||
import api from '../../utils/api'
|
||||
import { useTable, renderTableData } from '../../utils/table'
|
||||
|
||||
export default {
|
||||
name: 'ExamTable',
|
||||
setup() {
|
||||
const multipleTable = ref(null)
|
||||
const router = useRouter()
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
query: {
|
||||
page: 1,
|
||||
sort_field: 'id',
|
||||
sort_type: 'desc'
|
||||
},
|
||||
tableData: [], // 数据列表
|
||||
multipleSelection: [], // 选中项
|
||||
total: 0, // 总条数
|
||||
currentPage: 1, // 当前页
|
||||
pageSize: 10 // 分页大小
|
||||
})
|
||||
// const state = reactive({
|
||||
// loading: false,
|
||||
// query: {
|
||||
// page: 1,
|
||||
// sort_field: 'id',
|
||||
// sort_type: 'desc'
|
||||
// },
|
||||
// tableData: [], // 数据列表
|
||||
// multipleSelection: [], // 选中项
|
||||
// total: 0, // 总条数
|
||||
// currentPage: 1, // 当前页
|
||||
// pageSize: 10 // 分页大小
|
||||
// })
|
||||
|
||||
const state = useTable()
|
||||
|
||||
onMounted(() => {
|
||||
fetchTableData()
|
||||
})
|
||||
@@ -113,28 +123,35 @@ export default {
|
||||
const fetchTableData = async () => {
|
||||
state.loading = true
|
||||
let res = await api.listExam(state.query)
|
||||
renderTableData(res)
|
||||
}
|
||||
const renderTableData = (res) => {
|
||||
state.tableData = res.data.data
|
||||
state.page = res.data.meta.current_page
|
||||
state.total = res.data.meta.total
|
||||
state.currentPage = res.data.meta.current_page
|
||||
state.pageSize = res.data.meta.per_page
|
||||
renderTableData(res, state)
|
||||
state.loading = false
|
||||
}
|
||||
// const renderTableData = (res) => {
|
||||
// state.tableData = res.data.data
|
||||
// state.page = res.data.meta.current_page
|
||||
// state.total = res.data.meta.total
|
||||
// state.currentPage = res.data.meta.current_page
|
||||
// state.pageSize = res.data.meta.per_page
|
||||
// state.loading = false
|
||||
// }
|
||||
const handleAdd = () => {
|
||||
router.push({ name: 'exam-form' })
|
||||
}
|
||||
const handleEdit = (id) => {
|
||||
router.push({ path: '/exam-form', query: { id } })
|
||||
}
|
||||
const handleDelete = async (id) => {
|
||||
let res = await api.deleteExam(id)
|
||||
ElMessage.success(res.msg)
|
||||
state.query.page = 1;
|
||||
await fetchTableData()
|
||||
}
|
||||
// 选择项
|
||||
const handleSelectionChange = (val) => {
|
||||
state.multipleSelection = val
|
||||
}
|
||||
const changePage = (val) => {
|
||||
state.currentPage = val
|
||||
state.query.page = val
|
||||
fetchTableData()
|
||||
}
|
||||
const handleStatus = (id, status) => {
|
||||
@@ -151,6 +168,7 @@ export default {
|
||||
handleSelectionChange,
|
||||
handleAdd,
|
||||
handleEdit,
|
||||
handleDelete,
|
||||
fetchTableData,
|
||||
changePage,
|
||||
handleStatus
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
<template>
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="nexus-table-header">
|
||||
<div class="left">
|
||||
|
||||
</div>
|
||||
<div class="right">
|
||||
<el-button type="primary" size="small" icon="el-icon-plus" @click="handleAdd">Add</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
ref="multipleTable"
|
||||
:data="tableData"
|
||||
tooltip-effect="dark"
|
||||
@sort-change="handleSortChange"
|
||||
@selection-change="handleSelectionChange">
|
||||
|
||||
<el-table-column
|
||||
type="selection"
|
||||
width="55">
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="id"
|
||||
label="Id"
|
||||
width="60"
|
||||
sortable="custom"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="exam_id"
|
||||
label="Exam"
|
||||
:formatter="formatColumnExam"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="uid"
|
||||
label="User"
|
||||
:formatter="formatColumnUser"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="status_text"
|
||||
label="Status"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="created_at"
|
||||
label="Created At"
|
||||
>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
label="Action"
|
||||
width="100"
|
||||
>
|
||||
<!-- <template #default="scope">-->
|
||||
<!-- <a style="cursor: pointer; margin-right: 10px" @click="handleEdit(scope.row.id)">Edit</a>-->
|
||||
<!-- <el-popconfirm-->
|
||||
<!-- title="Confirm Delete ?"-->
|
||||
<!-- @confirm="handleDelete(scope.row.id)"-->
|
||||
<!-- >-->
|
||||
<!-- <template #reference>-->
|
||||
<!-- <a style="cursor: pointer">Delete</a>-->
|
||||
<!-- </template>-->
|
||||
<!-- </el-popconfirm>-->
|
||||
<!-- </template>-->
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!--总数超过一页,再展示分页器-->
|
||||
<el-pagination
|
||||
background
|
||||
layout="prev, pager, next"
|
||||
:total="total"
|
||||
:page-size="perPage"
|
||||
:current-page="currentPage"
|
||||
@current-change="changePage"
|
||||
/>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { onMounted, reactive, ref, toRefs } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useRouter } from 'vue-router'
|
||||
import api from '../../utils/api'
|
||||
import { useTable, renderTableData, resetTableSort } from '../../utils/table'
|
||||
|
||||
export default {
|
||||
name: 'ExamUserTable',
|
||||
setup() {
|
||||
const multipleTable = ref(null)
|
||||
const router = useRouter()
|
||||
|
||||
const state = useTable()
|
||||
|
||||
onMounted(() => {
|
||||
fetchTableData()
|
||||
})
|
||||
const fetchTableData = async () => {
|
||||
state.loading = true
|
||||
let res = await api.listExamUser(state.query)
|
||||
renderTableData(res, state)
|
||||
state.loading = false
|
||||
}
|
||||
const handleAdd = () => {
|
||||
router.push({ name: 'user-form' })
|
||||
}
|
||||
const handleEdit = (id) => {
|
||||
router.push({ name: 'user-form', query: { id } })
|
||||
}
|
||||
const handleDelete = async (id) => {
|
||||
let res = await api.deleteExam(id)
|
||||
ElMessage.success(res.msg)
|
||||
state.query.page = 1;
|
||||
await fetchTableData()
|
||||
}
|
||||
// 选择项
|
||||
const handleSelectionChange = (val) => {
|
||||
state.multipleSelection = val
|
||||
}
|
||||
const changePage = (val) => {
|
||||
state.query.page = val
|
||||
fetchTableData()
|
||||
}
|
||||
const handleSortChange = (val) => {
|
||||
resetTableSort(val, state)
|
||||
fetchTableData()
|
||||
}
|
||||
|
||||
const formatColumnUser = (row, column) => {
|
||||
return row.user.username
|
||||
}
|
||||
|
||||
const formatColumnExam = (row, column) => {
|
||||
return row.exam.name
|
||||
}
|
||||
const formatColumnDownloaded = (row, column) => {
|
||||
return row.downloaded_text
|
||||
}
|
||||
return {
|
||||
...toRefs(state),
|
||||
multipleTable,
|
||||
handleSelectionChange,
|
||||
handleAdd,
|
||||
handleEdit,
|
||||
handleDelete,
|
||||
fetchTableData,
|
||||
changePage,
|
||||
handleSortChange,
|
||||
formatColumnUser,
|
||||
formatColumnExam,
|
||||
formatColumnDownloaded
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.nexus-table-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
</style>
|
||||
@@ -1,3 +1,97 @@
|
||||
<template>
|
||||
<div>User Form</div>
|
||||
<div>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form :model="formData" :rules="rules" ref="formRef" label-width="200px" class="formData">
|
||||
|
||||
<el-form-item label="Username" prop="username">
|
||||
<el-input v-model="formData.username" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="Email" prop="email">
|
||||
<el-input v-model="formData.email" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="Password" prop="password">
|
||||
<el-input type="password" v-model="formData.password" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="Password Confirmation" prop="password_confirmation">
|
||||
<el-input type="password" v-model="formData.password_confirmation" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="submitAdd()">Submit</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { reactive, ref, toRefs, onMounted, onBeforeUnmount, getCurrentInstance } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { localGet } from '../../utils'
|
||||
import api from "../../utils/api";
|
||||
|
||||
export default {
|
||||
name: 'UserForm',
|
||||
setup() {
|
||||
const { proxy } = getCurrentInstance()
|
||||
console.log('proxy', proxy)
|
||||
const formRef = ref(null)
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { id } = route.query
|
||||
const state = reactive({
|
||||
id: id,
|
||||
formData: {
|
||||
username: '',
|
||||
email: '',
|
||||
password: '',
|
||||
password_confirmation: '',
|
||||
},
|
||||
rules: {
|
||||
username: [
|
||||
{ required: 'true'}
|
||||
],
|
||||
email: [
|
||||
{ required: 'true', type: 'email'}
|
||||
],
|
||||
password: [
|
||||
{ required: 'true', min: 6, max: 40}
|
||||
],
|
||||
password_confirmation: [
|
||||
{ required: 'true', min: 6, max: 40}
|
||||
],
|
||||
},
|
||||
})
|
||||
onMounted( () => {
|
||||
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
|
||||
})
|
||||
const submitAdd = () => {
|
||||
formRef.value.validate(async (vaild) => {
|
||||
if (vaild) {
|
||||
let params = state.formData;
|
||||
await api.storeUser(params)
|
||||
await router.push({name: 'user'})
|
||||
}
|
||||
})
|
||||
}
|
||||
return {
|
||||
...toRefs(state),
|
||||
formRef,
|
||||
submitAdd,
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
|
||||
@@ -1,3 +1,184 @@
|
||||
<template>
|
||||
<div>User Index</div>
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="header">
|
||||
<el-button type="primary" size="small" icon="el-icon-plus" @click="handleAdd">Add</el-button>
|
||||
</div>
|
||||
</template>
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
ref="multipleTable"
|
||||
:data="tableData"
|
||||
tooltip-effect="dark"
|
||||
@sort-change="handleSortChange"
|
||||
@selection-change="handleSelectionChange">
|
||||
|
||||
<el-table-column
|
||||
type="selection"
|
||||
width="55">
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="id"
|
||||
label="Id"
|
||||
width="60"
|
||||
sortable="custom"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="username"
|
||||
label="Username"
|
||||
sortable="custom"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="email"
|
||||
label="Email"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="class"
|
||||
label="Class"
|
||||
sortable="custom"
|
||||
:formatter="formatColumnClass"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="uploaded"
|
||||
label="Uploaded"
|
||||
sortable="custom"
|
||||
:formatter="formatColumnUploaded"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="downloaded"
|
||||
label="Downloaded"
|
||||
sortable="custom"
|
||||
:formatter="formatColumnDownloaded"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="bonus"
|
||||
label="Bonus"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="status"
|
||||
label="Status"
|
||||
></el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="added"
|
||||
label="Added"
|
||||
>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
label="Action"
|
||||
width="100"
|
||||
>
|
||||
<!-- <template #default="scope">-->
|
||||
<!-- <a style="cursor: pointer; margin-right: 10px" @click="handleEdit(scope.row.id)">Edit</a>-->
|
||||
<!-- <el-popconfirm-->
|
||||
<!-- title="Confirm Delete ?"-->
|
||||
<!-- @confirm="handleDelete(scope.row.id)"-->
|
||||
<!-- >-->
|
||||
<!-- <template #reference>-->
|
||||
<!-- <a style="cursor: pointer">Delete</a>-->
|
||||
<!-- </template>-->
|
||||
<!-- </el-popconfirm>-->
|
||||
<!-- </template>-->
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!--总数超过一页,再展示分页器-->
|
||||
<el-pagination
|
||||
background
|
||||
layout="prev, pager, next"
|
||||
:total="total"
|
||||
:page-size="perPage"
|
||||
:current-page="currentPage"
|
||||
@current-change="changePage"
|
||||
/>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { onMounted, reactive, ref, toRefs } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useRouter } from 'vue-router'
|
||||
import api from '../../utils/api'
|
||||
import { useTable, renderTableData, resetTableSort } from '../../utils/table'
|
||||
|
||||
export default {
|
||||
name: 'UserTable',
|
||||
setup() {
|
||||
const multipleTable = ref(null)
|
||||
const router = useRouter()
|
||||
|
||||
const state = useTable()
|
||||
|
||||
onMounted(() => {
|
||||
fetchTableData()
|
||||
})
|
||||
const fetchTableData = async () => {
|
||||
state.loading = true
|
||||
let res = await api.listUser(state.query)
|
||||
renderTableData(res, state)
|
||||
state.loading = false
|
||||
}
|
||||
const handleAdd = () => {
|
||||
router.push({ name: 'user-form' })
|
||||
}
|
||||
const handleEdit = (id) => {
|
||||
router.push({ name: 'user-form', query: { id } })
|
||||
}
|
||||
const handleDelete = async (id) => {
|
||||
let res = await api.deleteExam(id)
|
||||
ElMessage.success(res.msg)
|
||||
state.query.page = 1;
|
||||
await fetchTableData()
|
||||
}
|
||||
// 选择项
|
||||
const handleSelectionChange = (val) => {
|
||||
state.multipleSelection = val
|
||||
}
|
||||
const changePage = (val) => {
|
||||
state.query.page = val
|
||||
fetchTableData()
|
||||
}
|
||||
const handleSortChange = (val) => {
|
||||
resetTableSort(val, state)
|
||||
fetchTableData()
|
||||
}
|
||||
|
||||
const formatColumnClass = (row, column) => {
|
||||
return row.class_text
|
||||
}
|
||||
|
||||
const formatColumnUploaded = (row, column) => {
|
||||
return row.uploaded_text
|
||||
}
|
||||
const formatColumnDownloaded = (row, column) => {
|
||||
return row.downloaded_text
|
||||
}
|
||||
return {
|
||||
...toRefs(state),
|
||||
multipleTable,
|
||||
handleSelectionChange,
|
||||
handleAdd,
|
||||
handleEdit,
|
||||
handleDelete,
|
||||
fetchTableData,
|
||||
changePage,
|
||||
handleSortChange,
|
||||
formatColumnClass,
|
||||
formatColumnUploaded,
|
||||
formatColumnDownloaded
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Repositories\ExamRepository;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
@@ -38,6 +40,9 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
dd(strlen(Hash::make('123456')));
|
||||
$examRep = new ExamRepository();
|
||||
$user = User::query()->find(1);
|
||||
$r = $examRep->assignToUser($user->id);
|
||||
dd($r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\ExamResource;
|
||||
use App\Http\Resources\ExamUserResource;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Repositories\ExamRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
@@ -88,11 +89,12 @@ class ExamController extends Controller
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return array
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
$result = $this->repository->delete($id);
|
||||
return $this->success($result, 'Delete exam success!');
|
||||
}
|
||||
|
||||
public function indexes()
|
||||
@@ -101,4 +103,11 @@ class ExamController extends Controller
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
public function users(Request $request)
|
||||
{
|
||||
$result = $this->repository->listUser($request->all());
|
||||
$resource = ExamUserResource::collection($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\ExamResource;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Repositories\ExamRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class UserController extends Controller
|
||||
@@ -109,4 +112,13 @@ class UserController extends Controller
|
||||
$resource = new UserResource($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
public function exams()
|
||||
{
|
||||
$id = Auth::id();
|
||||
$examRepository = new ExamRepository();
|
||||
$result = $examRepository->listMatchExam($id);
|
||||
$resource = ExamResource::collection($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Exam;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ExamUserResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'status' => $this->status,
|
||||
'status_text' => $this->statusText,
|
||||
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
'exam' => new ExamResource($this->whenLoaded('exam')),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,9 +21,13 @@ class UserResource extends JsonResource
|
||||
'status' => $this->status,
|
||||
'added' => $this->added,
|
||||
'class' => $this->class,
|
||||
'class_text' => $this->class_text,
|
||||
'avatar' => $this->avatar,
|
||||
'uploaded' => $this->uploaded,
|
||||
'uploaded_text' => mksize($this->uploaded),
|
||||
'downloaded' => $this->downloaded,
|
||||
'downloaded_text' => mksize($this->downloaded),
|
||||
'bonus' => $this->seedbonus,
|
||||
'seedtime' => $this->seedtime,
|
||||
'leechtime' => $this->leechtime,
|
||||
];
|
||||
|
||||
@@ -6,6 +6,8 @@ class AgentAllow extends NexusModel
|
||||
{
|
||||
protected $table = 'agent_allowed_family';
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
protected $fillable = [
|
||||
'family', 'start_name', 'exception', 'allowhttps', 'comment',
|
||||
'peer_id_pattern', 'peer_id_match_num', 'peer_id_matchtype', 'peer_id_start',
|
||||
|
||||
@@ -6,6 +6,8 @@ class Exam extends NexusModel
|
||||
{
|
||||
protected $fillable = ['name', 'description', 'begin', 'end', 'status', 'filters', 'indexes'];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
protected $casts = [
|
||||
'filters' => 'object',
|
||||
'indexes' => 'array',
|
||||
|
||||
@@ -5,4 +5,6 @@ namespace App\Models;
|
||||
class ExamProgress extends NexusModel
|
||||
{
|
||||
protected $fillable = ['exam_id', 'uid', 'type_id', 'value'];
|
||||
|
||||
public $timestamps = true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class ExamUser extends NexusModel
|
||||
{
|
||||
protected $fillable = ['exam_id', 'uid', 'status', 'result'];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
const STATUS_NORMAL = 0;
|
||||
const STATUS_FINISHED = 1;
|
||||
|
||||
public static $status = [
|
||||
self::STATUS_NORMAL => ['text' => 'Normal'],
|
||||
self::STATUS_FINISHED => ['text' => 'Finished'],
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'result' => 'json'
|
||||
];
|
||||
|
||||
public function getStatusTextAttribute()
|
||||
{
|
||||
return self::$status[$this->status]['text'] ?? '';
|
||||
}
|
||||
|
||||
public function exam(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Exam::class, 'exam_id');
|
||||
}
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'uid');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,6 +11,8 @@ class NexusModel extends Model
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $perPage = 2;
|
||||
|
||||
/**
|
||||
* 为数组 / JSON 序列化准备日期。
|
||||
*
|
||||
|
||||
@@ -54,6 +54,8 @@ class User extends Authenticatable
|
||||
self::CLASS_STAFF_LEADER => ['text' => 'Staff Leader'],
|
||||
];
|
||||
|
||||
protected $perPage = 2;
|
||||
|
||||
public function getClassTextAttribute(): string
|
||||
{
|
||||
return self::$classes[$this->class]['text'] ?? '';
|
||||
@@ -96,4 +98,21 @@ class User extends Authenticatable
|
||||
protected $casts = [
|
||||
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'added'
|
||||
];
|
||||
|
||||
|
||||
public function exams(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Exam::class, 'exam_users', 'uid', 'exam_id')->withTimestamps();
|
||||
}
|
||||
|
||||
public function examDetails(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(ExamUser::class. 'uid');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Exam;
|
||||
use App\Models\ExamUser;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
@@ -20,27 +21,47 @@ class ExamRepository extends BaseRepository
|
||||
|
||||
public function store(array $params)
|
||||
{
|
||||
$data = Arr::only($params, ['name', 'description', 'status', 'filters']);
|
||||
if (!empty($params['begin'])) {
|
||||
|
||||
}
|
||||
$this->checkIndexes($params);
|
||||
$exam = Exam::query()->create($params);
|
||||
return $exam;
|
||||
}
|
||||
|
||||
public function update(array $params, $id)
|
||||
{
|
||||
$this->checkIndexes($params);
|
||||
$exam = Exam::query()->findOrFail($id);
|
||||
$exam->update($params);
|
||||
return $exam;
|
||||
}
|
||||
|
||||
private function checkIndexes(array $params)
|
||||
{
|
||||
if (empty($params['indexes'])) {
|
||||
throw new \InvalidArgumentException("Require index.");
|
||||
}
|
||||
$validIndex = array_filter($params['indexes'], function ($value) {
|
||||
return isset($value['checked']) && $value['checked']
|
||||
&& isset($value['require_value']) && $value['require_value'] > 0;
|
||||
});
|
||||
if (empty($validIndex)) {
|
||||
throw new \InvalidArgumentException("Require valid index.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDetail($id)
|
||||
{
|
||||
$exam = Exam::query()->findOrFail($id);
|
||||
return $exam;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$exam = Exam::query()->findOrFail($id);
|
||||
$result = $exam->delete();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function listIndexes()
|
||||
{
|
||||
$out = [];
|
||||
@@ -51,52 +72,122 @@ class ExamRepository extends BaseRepository
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function listFilters()
|
||||
/**
|
||||
* list valid exams
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function listValid()
|
||||
{
|
||||
$out = [];
|
||||
foreach(Exam::$filters as $key => $value) {
|
||||
$value['filter'] = $key;
|
||||
$out[] = $value;
|
||||
}
|
||||
return $out;
|
||||
$now = Carbon::now();
|
||||
return Exam::query()
|
||||
->where('begin', '<=', $now)
|
||||
->where('end', '>=', $now)
|
||||
->where('status', Exam::STATUS_ENABLED)
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* list user match exams
|
||||
*
|
||||
* @param $uid
|
||||
* @return array
|
||||
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function listMatchExam($uid): array
|
||||
public function listMatchExam($uid)
|
||||
{
|
||||
$now = Carbon::now();
|
||||
$user = User::query()->findOrFail($uid, ['id', 'username', 'added', 'class']);
|
||||
$exams = Exam::query()
|
||||
->where('begin', '<=', $now)
|
||||
->where('end', '>=', $now)
|
||||
->where('status', Exam::STATUS_ENABLED)
|
||||
->get();
|
||||
$result = [];
|
||||
$logPrefix = "uid: $uid";
|
||||
foreach ($exams as $exam) {
|
||||
$filters = $exam->filters;
|
||||
if (!in_array($user->class, $filters['classes'])) {
|
||||
Log::info("$logPrefix, class: {$user->class} not in: " . json_encode($filters));
|
||||
continue;
|
||||
}
|
||||
$added = $user->added->toDateTimeString();
|
||||
if (!empty($filters['register_time_begin']) && $added < $filters['register_time_begin']) {
|
||||
Log::info("$logPrefix, added: $added not after: " . $filters['register_time_begin']);
|
||||
continue;
|
||||
}
|
||||
if (!empty($filters['register_time_end']) && $added > $filters['register_time_end']) {
|
||||
Log::info("$logPrefix, added: $added not before: " . $filters['register_time_end']);
|
||||
continue;
|
||||
}
|
||||
$result[] = $exam;
|
||||
$exams = $this->listValid();
|
||||
if ($exams->isEmpty()) {
|
||||
Log::info("$logPrefix, no valid exam.");
|
||||
return $exams;
|
||||
}
|
||||
$user = User::query()->findOrFail($uid, ['id', 'username', 'added', 'class']);
|
||||
|
||||
$filtered = $exams->filter(function (Exam $exam) use ($user, $logPrefix) {
|
||||
$filters = $exam->filters;
|
||||
if (empty($filters->classes)) {
|
||||
Log::info("$logPrefix, exam: {$exam->id} no class");
|
||||
return false;
|
||||
}
|
||||
if (!in_array($user->class, $filters->classes)) {
|
||||
Log::info("$logPrefix, user class: {$user->class} not in: " . json_encode($filters));
|
||||
return false;
|
||||
}
|
||||
|
||||
$added = $user->added->toDateTimeString();
|
||||
$registerTimeBegin = $filters->register_time_range[0] ? Carbon::parse($filters->register_time_range[0])->toDateString() : '';
|
||||
$registerTimeEnd = $filters->register_time_range[1] ? Carbon::parse($filters->register_time_range[1])->toDateString() : '';
|
||||
if (empty($registerTimeBegin)) {
|
||||
Log::info("$logPrefix, exam: {$exam->id} no register_time_begin");
|
||||
return false;
|
||||
}
|
||||
if ($added < $registerTimeBegin) {
|
||||
Log::info("$logPrefix, added: $added not after: " . $registerTimeBegin);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($registerTimeEnd)) {
|
||||
Log::info("$logPrefix, exam: {$exam->id} no register_time_end");
|
||||
return false;
|
||||
}
|
||||
if ($added > $registerTimeEnd) {
|
||||
Log::info("$logPrefix, added: $added not before: " . $registerTimeEnd);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* assign exam to user
|
||||
*
|
||||
* @param $uid
|
||||
* @param int $examId
|
||||
* @return mixed
|
||||
*/
|
||||
public function assignToUser($uid, $examId = 0)
|
||||
{
|
||||
if ($examId > 0) {
|
||||
$exam = Exam::query()->find($examId);
|
||||
} else {
|
||||
$exams = $this->listMatchExam($uid);
|
||||
if ($exams->count() > 1) {
|
||||
throw new \LogicException("Match exam more than 1.");
|
||||
}
|
||||
$exam = $exams->first();
|
||||
}
|
||||
if (!$exam) {
|
||||
throw new \LogicException("No valid exam.");
|
||||
}
|
||||
$user = User::query()->findOrFail($uid);
|
||||
$exists = $user->exams()->where('exam_id', $exam->id)->exists();
|
||||
if ($exists) {
|
||||
throw new \LogicException("exam: {$exam->id} already assign to user: {$user->id}");
|
||||
}
|
||||
$result = $user->exams()->save($exam);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function listUser(array $params)
|
||||
{
|
||||
$query = ExamUser::query();
|
||||
if (!empty($params['uid'])) {
|
||||
$query->where('uid', $params['uid']);
|
||||
}
|
||||
if (!empty($params['exam_id'])) {
|
||||
$query->where('exam_id', $params['exam_id']);
|
||||
}
|
||||
list($sortField, $sortType) = $this->getSortFieldAndType($params);
|
||||
$query->orderBy($sortField, $sortType);
|
||||
$result = $query->with(['user', 'exam'])->paginate();
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateExamUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('exam_users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('uid')->index();
|
||||
$table->integer('exam_id')->index();
|
||||
$table->integer('status')->default(0);
|
||||
$table->text('result')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('exam_users');
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,9 @@ Route::group(['middleware' => ['auth:sanctum']], function () {
|
||||
Route::resource('agent-allow', \App\Http\Controllers\AgentAllowController::class);
|
||||
Route::resource('user', \App\Http\Controllers\UserController::class);
|
||||
Route::get('user-base', [\App\Http\Controllers\UserController::class, 'base']);
|
||||
Route::get('user-exams', [\App\Http\Controllers\UserController::class, 'exams']);
|
||||
Route::resource('exam', \App\Http\Controllers\ExamController::class);
|
||||
Route::get('exam-users', [\App\Http\Controllers\ExamController::class, 'users']);
|
||||
Route::get('exam-index', [\App\Http\Controllers\ExamController::class, 'indexes']);
|
||||
Route::get('class', [\App\Http\Controllers\UserController::class, 'classes']);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user