增加课程资源管理,对应数据表train_resource
This commit is contained in:
1 parent
1162f26e7d
commit
abb042ff1a
8 files changed
+1051
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 查询教学资源列表
|
||||
export function listResource(query) {
|
||||
return request({
|
||||
url: '/train/resource/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 查询教学资源详细
|
||||
export function getResource(resourceId) {
|
||||
return request({
|
||||
url: '/train/resource/' + resourceId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 新增教学资源
|
||||
export function addResource(data) {
|
||||
return request({
|
||||
url: '/train/resource',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改教学资源
|
||||
export function updateResource(data) {
|
||||
return request({
|
||||
url: '/train/resource/' + data.resourceId,
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除教学资源
|
||||
export function delResource(resourceId) {
|
||||
return request({
|
||||
url: '/train/resource/' + resourceId,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="68px">
|
||||
<el-form-item label="资源名称" prop="resourceName">
|
||||
<el-input
|
||||
v-model="queryParams.resourceName"
|
||||
placeholder="请输入资源名称"
|
||||
clearable
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="资源类型" prop="resourceType">
|
||||
<el-select v-model="queryParams.resourceType" placeholder="资源类型" clearable>
|
||||
<el-option
|
||||
v-for="dict in resourceTypeOptions"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="资源状态" clearable>
|
||||
<el-option label="正常" :value="1" />
|
||||
<el-option label="停用" :value="0" />
|
||||
</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
|
||||
v-hasPermi="['train:resource:edit']"
|
||||
type="primary"
|
||||
plain
|
||||
icon="el-icon-plus"
|
||||
size="mini"
|
||||
@click="handleAdd"
|
||||
>新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
v-hasPermi="['train:resource:edit']"
|
||||
type="success"
|
||||
plain
|
||||
icon="el-icon-edit"
|
||||
size="mini"
|
||||
:disabled="single"
|
||||
@click="handleUpdate"
|
||||
>修改</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
v-hasPermi="['train:resource:edit']"
|
||||
type="danger"
|
||||
plain
|
||||
icon="el-icon-delete"
|
||||
size="mini"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
>删除</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="resourceList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="资源名称" align="center" prop="resourceName" min-width="160" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="资源类型" align="center" prop="resourceType">
|
||||
<template slot-scope="scope">
|
||||
<dict-tag :options="dict.type.train_resource_type" :value="scope.row.resourceType" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="资源文件/地址" align="center" prop="resourceUrl" min-width="200" :show-overflow-tooltip="true">
|
||||
<template slot-scope="scope">
|
||||
<el-link
|
||||
v-if="scope.row.resourceType === 5"
|
||||
:href="scope.row.resourceUrl"
|
||||
type="primary"
|
||||
target="_blank"
|
||||
:underline="false"
|
||||
>{{ scope.row.resourceUrl }}</el-link>
|
||||
<el-link
|
||||
v-else
|
||||
:href="fileUrl(scope.row.resourceUrl)"
|
||||
type="primary"
|
||||
target="_blank"
|
||||
:underline="false"
|
||||
>{{ fileName(scope.row.resourceUrl) }}</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="资源描述" align="center" prop="description" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="状态" align="center" prop="status">
|
||||
<template slot-scope="scope">
|
||||
<el-tag v-if="scope.row.status === 1" type="success">正常</el-tag>
|
||||
<el-tag v-else type="danger">停用</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" width="160">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
v-hasPermi="['train:resource:edit']"
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-edit"
|
||||
@click="handleUpdate(scope.row)"
|
||||
>修改</el-button>
|
||||
<el-button
|
||||
v-hasPermi="['train:resource:edit']"
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope.row)"
|
||||
>删除</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="600px" append-to-body>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="资源名称" prop="resourceName">
|
||||
<el-input v-model="form.resourceName" placeholder="请输入资源名称" maxlength="150" />
|
||||
</el-form-item>
|
||||
<el-form-item label="资源类型" prop="resourceType">
|
||||
<el-select v-model="form.resourceType" placeholder="请选择资源类型" style="width: 100%">
|
||||
<el-option
|
||||
v-for="dict in resourceTypeOptions"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="isExternalLink" label="外部链接" prop="resourceUrl">
|
||||
<el-input v-model="form.resourceUrl" placeholder="请输入外部教学链接,以 http(s):// 开头" maxlength="500" />
|
||||
</el-form-item>
|
||||
<el-form-item v-else label="资源文件" prop="resourceUrl">
|
||||
<file-upload
|
||||
v-model="form.resourceUrl"
|
||||
:limit="1"
|
||||
:file-size="100"
|
||||
:file-type="fileTypes"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="资源描述" prop="description">
|
||||
<el-input v-model="form.description" type="textarea" :rows="3" maxlength="500" placeholder="请输入资源描述/使用说明" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-radio-group v-model="form.status">
|
||||
<el-radio :label="1">正常</el-radio>
|
||||
<el-radio :label="0">停用</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" placeholder="请输入备注" maxlength="500" />
|
||||
</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>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listResource, getResource, addResource, updateResource, delResource } from '@/api/train/resource'
|
||||
|
||||
export default {
|
||||
name: 'TrainResource',
|
||||
dicts: ['train_resource_type'],
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 选中数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 总条数
|
||||
total: 0,
|
||||
// 教学资源表格数据
|
||||
resourceList: [],
|
||||
// 弹出层标题
|
||||
title: '',
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
// 允许上传的资源文件格式
|
||||
fileTypes: ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'txt', 'zip', 'rar', '7z', 'mp4', 'avi', 'mov', 'wmv', 'mp3', 'png', 'jpg', 'jpeg', 'gif', 'glb', 'gltf', 'obj', 'fbx'],
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
resourceName: null,
|
||||
resourceType: null,
|
||||
status: null
|
||||
},
|
||||
// 表单参数
|
||||
form: {},
|
||||
// 表单校验
|
||||
rules: {
|
||||
resourceName: [
|
||||
{ required: true, message: '资源名称不能为空', trigger: 'blur' }
|
||||
],
|
||||
resourceType: [
|
||||
{ required: true, message: '资源类型不能为空', trigger: 'change' }
|
||||
],
|
||||
resourceUrl: [
|
||||
{ required: true, message: '资源文件或外部链接不能为空', trigger: ['blur', 'change'] }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
// 资源类型下拉项:字典值为字符串,数据表字段为整型,需转成数字
|
||||
resourceTypeOptions() {
|
||||
return (this.dict.type.train_resource_type || []).map(item => ({
|
||||
label: item.label,
|
||||
value: /^\d+$/.test(String(item.value)) ? Number(item.value) : item.value
|
||||
}))
|
||||
},
|
||||
// 资源类型为「外部教学链接」时不走上传,改为填写地址
|
||||
isExternalLink() {
|
||||
return Number(this.form.resourceType) === 5
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
// 切换资源类型时清空已选资源地址,避免类型与地址不匹配
|
||||
'form.resourceType'(newVal, oldVal) {
|
||||
if (oldVal !== undefined && newVal !== oldVal && this.open) {
|
||||
this.$set(this.form, 'resourceUrl', null)
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs['form']) {
|
||||
this.$refs['form'].clearValidate('resourceUrl')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getList()
|
||||
},
|
||||
methods: {
|
||||
/** 查询教学资源列表 */
|
||||
getList() {
|
||||
this.loading = true
|
||||
listResource(this.queryParams).then(response => {
|
||||
this.resourceList = response.rows
|
||||
this.total = response.total
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
this.open = false
|
||||
this.reset()
|
||||
},
|
||||
// 表单重置
|
||||
reset() {
|
||||
this.form = {
|
||||
resourceId: null,
|
||||
resourceName: null,
|
||||
resourceType: 1,
|
||||
resourceUrl: null,
|
||||
description: null,
|
||||
status: 1,
|
||||
remark: null
|
||||
}
|
||||
this.resetForm('form')
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.queryParams.pageNum = 1
|
||||
this.getList()
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
this.resetForm('queryForm')
|
||||
this.handleQuery()
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map(item => item.resourceId)
|
||||
this.single = selection.length !== 1
|
||||
this.multiple = !selection.length
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset()
|
||||
this.open = true
|
||||
this.title = '添加教学资源'
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset()
|
||||
const resourceId = row.resourceId || this.ids
|
||||
getResource(resourceId).then(response => {
|
||||
// 资源类型为整型,防止后端返回字符串导致下拉/单选回显失败
|
||||
this.form = {
|
||||
...response.data,
|
||||
resourceType: response.data.resourceType == null ? null : Number(response.data.resourceType),
|
||||
status: response.data.status == null ? 1 : Number(response.data.status)
|
||||
}
|
||||
this.open = true
|
||||
this.title = '修改教学资源'
|
||||
})
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm() {
|
||||
this.$refs['form'].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.resourceId != null) {
|
||||
updateResource(this.form).then(response => {
|
||||
this.$modal.msgSuccess('修改成功')
|
||||
this.open = false
|
||||
this.getList()
|
||||
})
|
||||
} else {
|
||||
addResource(this.form).then(response => {
|
||||
this.$modal.msgSuccess('新增成功')
|
||||
this.open = false
|
||||
this.getList()
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const ids = row.resourceId || this.ids
|
||||
if (!ids || (Array.isArray(ids) && ids.length === 0)) {
|
||||
this.$modal.msgWarning('请选择要删除的数据')
|
||||
return
|
||||
}
|
||||
this.$modal.confirm('是否确认删除资源编号为"' + ids + '"的数据项?').then(function() {
|
||||
return delResource(ids)
|
||||
}).then(() => {
|
||||
this.getList()
|
||||
this.$modal.msgSuccess('删除成功')
|
||||
}).catch(() => {})
|
||||
},
|
||||
// 资源文件访问地址
|
||||
fileUrl(url) {
|
||||
if (!url) {
|
||||
return ''
|
||||
}
|
||||
if (/^(http|https):\/\//.test(url)) {
|
||||
return url
|
||||
}
|
||||
return process.env.VUE_APP_BASE_API + url
|
||||
},
|
||||
// 资源文件名
|
||||
fileName(url) {
|
||||
if (!url) {
|
||||
return ''
|
||||
}
|
||||
return url.substring(url.lastIndexOf('/') + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user