|
@@ -0,0 +1,262 @@
|
|
|
+<!-- -->
|
|
|
+<template>
|
|
|
+ <div class="book-vocab">
|
|
|
+ <div class="book-vocab-content">
|
|
|
+ <el-form ref="searchForm" :model="searchForm" :rules="courseListRules" size="mini">
|
|
|
+ <el-form-item label="资源键值" label-width="90px" prop="resource_key">
|
|
|
+ <el-input
|
|
|
+ v-model="searchForm.resource_key"
|
|
|
+ autocomplete="off"
|
|
|
+ placeholder="请输入资源键值"
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="资源名称" label-width="90px" prop="name">
|
|
|
+ <el-input v-model="searchForm.name" placeholder="请输入资源名称"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="备注" label-width="90px" prop="memo">
|
|
|
+ <el-input
|
|
|
+ v-model="searchForm.memo"
|
|
|
+ placeholder="请输入资源备注"
|
|
|
+ type="textarea"
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="上传资源" label-width="90px" prop="fileList">
|
|
|
+ <el-upload
|
|
|
+ :action="url"
|
|
|
+ :limit="1"
|
|
|
+ :on-exceed="handleExceed"
|
|
|
+ :on-preview="handlePreview"
|
|
|
+ :on-remove="handleRemove"
|
|
|
+ :http-request="upload"
|
|
|
+ accept="*"
|
|
|
+ class="upload-demo"
|
|
|
+ list-type="picture"
|
|
|
+ >
|
|
|
+ <el-button size="mini" type="success">点击上传</el-button>
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <el-button
|
|
|
+ v-if="resource_key === ''"
|
|
|
+ class="submitBtn"
|
|
|
+ size="mini"
|
|
|
+ type="primary"
|
|
|
+ @click="saveWord"
|
|
|
+ >保存资源</el-button
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { validNull } from '@/utils/validate';
|
|
|
+import { getContent } from '@/api/ajax';
|
|
|
+import { fileUpload } from '@/api/app';
|
|
|
+
|
|
|
+export default {
|
|
|
+ components: {},
|
|
|
+ props: {
|
|
|
+ resource_key: {
|
|
|
+ default: '',
|
|
|
+ type: String
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ const validateNull = (rule, value, callback) => {
|
|
|
+ if (!validNull(value)) {
|
|
|
+ callback(new Error('请输入相应内容'));
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ return {
|
|
|
+ isData: false,
|
|
|
+ isSaving: false,
|
|
|
+ searchForm: {
|
|
|
+ resource_key: '',
|
|
|
+ memo: '',
|
|
|
+ name: ''
|
|
|
+ },
|
|
|
+ fileList: [], // 上传图片数组
|
|
|
+ courseListRules: {
|
|
|
+ // 填写规则
|
|
|
+ resource_key: [{ required: true, trigger: 'blur', validator: validateNull }],
|
|
|
+ name: [{ required: true, trigger: 'blur', validator: validateNull }],
|
|
|
+ memo: [{ required: true, trigger: 'blur', validator: validateNull }]
|
|
|
+ // price: [
|
|
|
+ // { required: true, },
|
|
|
+ // ],
|
|
|
+ }
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ url() {
|
|
|
+ return process.env.VUE_APP_BASE_API + '/GCLSFileServer/WebFileUpload';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ resource_key: {
|
|
|
+ handler: function (val, oldVal) {
|
|
|
+ this.$refs.searchForm.resetFields();
|
|
|
+ if (val) {
|
|
|
+ this.searchForm.resource_key = this.resource_key;
|
|
|
+ if (this.resource_key !== '') {
|
|
|
+ this.getDetail();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.resource_key = '';
|
|
|
+ this.searchForm.name = '';
|
|
|
+ this.searchForm.resource_key = '';
|
|
|
+ this.searchForm.memo = '';
|
|
|
+ this.fileList = [];
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deep: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.searchForm.resource_key = this.resource_key;
|
|
|
+ if (this.resource_key !== '') {
|
|
|
+ this.getDetail();
|
|
|
+ } else {
|
|
|
+ this.resource_key = '';
|
|
|
+ this.searchForm.name = '';
|
|
|
+ this.searchForm.resource_key = '';
|
|
|
+ this.searchForm.memo = '';
|
|
|
+ this.fileList = [];
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 方法集合
|
|
|
+ methods: {
|
|
|
+ saveWord() {
|
|
|
+ this.$refs.searchForm.validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ this.isSaving = true;
|
|
|
+ let MethodName = 'file_resource_manager-InputFileResource';
|
|
|
+ const data_list = [];
|
|
|
+ this.fileList.forEach((item, index) => {
|
|
|
+ if (item.file_id) {
|
|
|
+ let obj = {
|
|
|
+ resource_key: this.searchForm.resource_key.trim(),
|
|
|
+ file_id: item.file_id,
|
|
|
+ memo: this.searchForm.memo.trim(),
|
|
|
+ name: this.searchForm.name.trim()
|
|
|
+ };
|
|
|
+ data_list.push(obj);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ let data = {
|
|
|
+ file_list: data_list
|
|
|
+ };
|
|
|
+ getContent(MethodName, data)
|
|
|
+ .then(res => {
|
|
|
+ this.$message.success('保存成功');
|
|
|
+ this.isSaving = false;
|
|
|
+ this.resource_key = '';
|
|
|
+ this.searchForm.name = '';
|
|
|
+ this.searchForm.resource_key = '';
|
|
|
+ this.searchForm.memo = '';
|
|
|
+ this.fileList = [];
|
|
|
+ this.$emit('closeDialog');
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ this.isSaving = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ upload(file) {
|
|
|
+ fileUpload('Open', file).then(response => {
|
|
|
+ if (response.status === 1) {
|
|
|
+ this.fileList = response.file_info_list;
|
|
|
+ this.$message.success('上传成功');
|
|
|
+ } else {
|
|
|
+ this.$message.warning(response.error);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ handleRemove(file, fileList) {
|
|
|
+ this.fileList = fileList;
|
|
|
+ },
|
|
|
+ handlePreview(file) {
|
|
|
+ console.log(file);
|
|
|
+ },
|
|
|
+ // 如果传参不为空 查询详情
|
|
|
+ getDetail() {
|
|
|
+ let MethodName = 'file_resource_manager-GetFileResource';
|
|
|
+ let data_list = [];
|
|
|
+ data_list.push(this.resource_key);
|
|
|
+ let data = {
|
|
|
+ resource_key_list: data_list
|
|
|
+ };
|
|
|
+ getContent(MethodName, data)
|
|
|
+ .then(res => {
|
|
|
+ res.file_list.forEach((item, index) => {
|
|
|
+ this.searchForm = item;
|
|
|
+ if (item.file_url) {
|
|
|
+ let obj = {
|
|
|
+ name: '',
|
|
|
+ url: item.file_url
|
|
|
+ };
|
|
|
+ this.fileList.push(obj);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch(() => {});
|
|
|
+ },
|
|
|
+ handleExceed(files, fileList) {
|
|
|
+ this.$message.warning(
|
|
|
+ `当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
|
|
|
+ files.length + fileList.length
|
|
|
+ } 个文件`
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } // 如果页面有keep-alive缓存功能,这个函数会触发
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+//@import url(); 引入公共css类
|
|
|
+.book-vocab {
|
|
|
+ width: 100%;
|
|
|
+ height: 100vh;
|
|
|
+ overflow: hidden;
|
|
|
+
|
|
|
+ &-content {
|
|
|
+ margin: 0 auto;
|
|
|
+ padding: 30px 0;
|
|
|
+
|
|
|
+ .changeLang {
|
|
|
+ margin-right: 10px;
|
|
|
+ }
|
|
|
+
|
|
|
+ &-create {
|
|
|
+ width: 100%;
|
|
|
+ display: flex;
|
|
|
+ justify-content: flex-start;
|
|
|
+ align-items: center;
|
|
|
+ margin-bottom: 20px;
|
|
|
+ }
|
|
|
+
|
|
|
+ &-search {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ align-items: flex-start;
|
|
|
+ }
|
|
|
+
|
|
|
+ &-table {
|
|
|
+ width: 100%;
|
|
|
+ height: calc(100vh - 120px);
|
|
|
+ overflow-y: scroll;
|
|
|
+ }
|
|
|
+
|
|
|
+ &-pag {
|
|
|
+ padding-top: 30px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.submitBtn {
|
|
|
+ margin-left: 90px;
|
|
|
+}
|
|
|
+</style>
|