|
|
@@ -1,161 +1,180 @@
|
|
|
<template>
|
|
|
- <div>
|
|
|
- <el-form :model="formData" :rules="rules" ref="form" label-width="80px" label-position="right" size="small"
|
|
|
- style="max-width: 500px;">
|
|
|
- <el-form-item prop="url" label="资源上传">
|
|
|
- <el-input v-model="formData.url" ></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="url" label="资源上传">
|
|
|
- <el-upload class="upload-demo" :file-list="fileList" :multiple="false" :action="$baseUrl+'/assets/uploadFile'" :on-success='haleSuccess'>
|
|
|
- <el-button size="small" type="primary">点击上传</el-button>
|
|
|
- <div slot="tip" class="el-upload__tip">文件大小限制 </div>
|
|
|
- </el-upload>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="type" label="类型:0:data_video 1:data_app">
|
|
|
- <template>
|
|
|
- <el-select v-model="formData.type" clearable placeholder="请选择" :disabled="subType!=''">
|
|
|
- <el-option
|
|
|
- v-for="item in typeOptions"
|
|
|
- :key="item.value"
|
|
|
- :label="item.label"
|
|
|
- :value="item.value">
|
|
|
- </el-option>
|
|
|
- </el-select>
|
|
|
- </template>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item v-if="formData.type==0" prop="image" label="video配图">
|
|
|
- <single-upload v-model="formData.image" :disabled="'imgUrl'==subColumn"></single-upload>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="fatherId" label="父类id">
|
|
|
- <el-input type="number" v-model="formData.fatherId" :disabled="'fatherId'==subColumn"></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item>
|
|
|
- <el-button @click="onSave" :loading="$store.state.fetchingData" type="primary">保存</el-button>
|
|
|
- <el-button @click="onDelete" v-if="formData.id" type="danger">删除</el-button>
|
|
|
- <el-button @click="$router.go(-1)">取消</el-button>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- </div>
|
|
|
+ <div>
|
|
|
+ <el-form
|
|
|
+ :model="formData"
|
|
|
+ :rules="rules"
|
|
|
+ ref="form"
|
|
|
+ label-width="80px"
|
|
|
+ label-position="right"
|
|
|
+ size="small"
|
|
|
+ style="max-width: 500px;"
|
|
|
+ >
|
|
|
+ <el-form-item prop="url" label="资源地址">
|
|
|
+ <el-input v-model="formData.url" :disabled="true"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="url" label="资源上传">
|
|
|
+ <el-upload
|
|
|
+ class="upload-demo"
|
|
|
+ :file-list="fileList"
|
|
|
+ :multiple="false"
|
|
|
+ :action="$baseUrl+'/assets/uploadFile'"
|
|
|
+ :on-success="haleSuccess"
|
|
|
+ >
|
|
|
+ <el-button size="small" type="primary">点击上传</el-button>
|
|
|
+ <div slot="tip" class="el-upload__tip">文件大小限制</div>
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item v-if="formData.type<0" prop="type" label="类型:0:data_video 1:data_app">
|
|
|
+ <template>
|
|
|
+ <el-select v-model="formData.type" clearable placeholder="请选择" :disabled="subType!=''">
|
|
|
+ <el-option
|
|
|
+ v-for="item in typeOptions"
|
|
|
+ :key="item.value"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.value"
|
|
|
+ ></el-option>
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item v-if="formData.type==0" prop="image" label="video配图">
|
|
|
+ <single-upload v-model="formData.image" :disabled="'imgUrl'==subColumn"></single-upload>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item v-if="formData.type<0" prop="fatherId" label="父类id">
|
|
|
+ <el-input type="number" v-model="formData.fatherId" :disabled="'fatherId'==subColumn"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button @click="onSave" :loading="$store.state.fetchingData" type="primary">保存</el-button>
|
|
|
+ <el-button @click="onDelete" v-if="formData.id" type="danger">删除</el-button>
|
|
|
+ <el-button @click="$router.go(-1)">取消</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
<script>
|
|
|
- import formValidator from '../formValidator'
|
|
|
+import formValidator from "../formValidator";
|
|
|
|
|
|
- export default {
|
|
|
- created() {
|
|
|
- if (this.$route.query.column) {
|
|
|
- this.subColumn = this.$route.query.column.split(',')[1];
|
|
|
- this.subValue = this.$route.query.column.split(',')[0];
|
|
|
- }
|
|
|
-
|
|
|
- if (this.$route.query.type>=0) {
|
|
|
- this.subType = this.$route.query.type;
|
|
|
- }
|
|
|
-
|
|
|
- if (this.$route.query.id) {
|
|
|
- this.$http.get({
|
|
|
- url: '/fileInfo/getOne',
|
|
|
- data: {
|
|
|
- id: this.$route.query.id
|
|
|
- }
|
|
|
- }).then(res => {
|
|
|
- if (res.success) {
|
|
|
-
|
|
|
-
|
|
|
- this.formData = res.data;
|
|
|
+export default {
|
|
|
+ created() {
|
|
|
+ if (this.$route.query.column) {
|
|
|
+ this.subColumn = this.$route.query.column.split(",")[1];
|
|
|
+ this.subValue = this.$route.query.column.split(",")[0];
|
|
|
+ }
|
|
|
|
|
|
- if (this.$route.query.column) {
|
|
|
- this.formData[this.subColumn] = this.subValue;
|
|
|
- }
|
|
|
- var nameList = res.data.url.split('/')
|
|
|
- var jsonp = {
|
|
|
- name: nameList[nameList.length - 1],
|
|
|
- url: res.data.url
|
|
|
- }
|
|
|
- this.fileList.push(jsonp)
|
|
|
+ if (this.$route.query.type >= 0) {
|
|
|
+ this.subType = this.$route.query.type;
|
|
|
+ }
|
|
|
|
|
|
- if (this.$route.query.type>=0) {
|
|
|
- this.formData.type = Number(this.subType);
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- if (this.$route.query.column) {
|
|
|
- this.formData[this.subColumn] = this.subValue;
|
|
|
- }
|
|
|
+ if (this.$route.query.id) {
|
|
|
+ this.$http
|
|
|
+ .get({
|
|
|
+ url: "/fileInfo/getOne",
|
|
|
+ data: {
|
|
|
+ id: this.$route.query.id
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ if (res.success) {
|
|
|
+ this.formData = res.data;
|
|
|
|
|
|
- if (this.$route.query.type>=0) {
|
|
|
- this.formData.type = Number(this.subType);
|
|
|
- }
|
|
|
+ if (this.$route.query.column) {
|
|
|
+ this.formData[this.subColumn] = this.subValue;
|
|
|
}
|
|
|
+ var nameList = res.data.url.split("/");
|
|
|
+ var jsonp = {
|
|
|
+ name: nameList[nameList.length - 1],
|
|
|
+ url: res.data.url
|
|
|
+ };
|
|
|
+ this.fileList.push(jsonp);
|
|
|
|
|
|
- },
|
|
|
- data() {
|
|
|
- return {
|
|
|
- saving: false,
|
|
|
- formData: {},
|
|
|
- rules: {},
|
|
|
- typeOptions:[{ value: 0, label: 'video' }, { value: 1, label: 'app' }],
|
|
|
- subColumn: '',
|
|
|
- subValue: '',
|
|
|
- fileList: [],
|
|
|
- subType: '',
|
|
|
+ if (this.$route.query.type >= 0) {
|
|
|
+ this.formData.type = Number(this.subType);
|
|
|
}
|
|
|
- },
|
|
|
- methods: {
|
|
|
- onSave() {
|
|
|
- this.$refs.form.validate((valid) => {
|
|
|
- if (valid) {
|
|
|
- this.submit();
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- submit() {
|
|
|
- var data = JSON.parse(JSON.stringify(this.formData));
|
|
|
- this.$http.post({
|
|
|
- url: this.formData.id ? '/fileInfo/update' : '/fileInfo/save',
|
|
|
- data: data
|
|
|
- }).then(res => {
|
|
|
- if (res.success) {
|
|
|
- this.$message.success('成功');
|
|
|
- this.$router.go(-1);
|
|
|
- } else {
|
|
|
- this.$message.warning('失败')
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- haleSuccess(file) {
|
|
|
- // console.log(file)
|
|
|
- file.data.forEach(item => {
|
|
|
- var nameList = item.split('/')
|
|
|
- var jsonp = {
|
|
|
- name: nameList[nameList.length - 1],
|
|
|
- url: item
|
|
|
- }
|
|
|
- this.fileList.splice(0, 1, jsonp)
|
|
|
- this.formData.url = item
|
|
|
- })
|
|
|
- },
|
|
|
- onDelete() {
|
|
|
- this.$alert('删除将无法恢复,确认要删除么?', '警告', {type: 'error'}).then(() => {
|
|
|
- return this.$http.post({
|
|
|
- url: '/fileInfo/del',
|
|
|
- data: {id: this.formData.id}
|
|
|
- })
|
|
|
- }).then(() => {
|
|
|
- this.$message.success('删除成功');
|
|
|
- this.$router.go(-1);
|
|
|
- }).catch(action => {
|
|
|
- if (action === 'cancel') {
|
|
|
- this.$message.info('删除取消');
|
|
|
- } else {
|
|
|
- this.$message.error('删除失败');
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ if (this.$route.query.column) {
|
|
|
+ this.formData[this.subColumn] = this.subValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.$route.query.type >= 0) {
|
|
|
+ this.formData.type = Number(this.subType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ saving: false,
|
|
|
+ formData: {},
|
|
|
+ rules: {
|
|
|
+ url: [{ required: true, message: "请上传资源", trigger: "blur" }],
|
|
|
+ },
|
|
|
+ typeOptions: [{ value: 0, label: "video" }, { value: 1, label: "app" }],
|
|
|
+ subColumn: "",
|
|
|
+ subValue: "",
|
|
|
+ fileList: [],
|
|
|
+ subType: ""
|
|
|
+ };
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ onSave() {
|
|
|
+ this.$refs.form.validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ this.submit();
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
}
|
|
|
+ });
|
|
|
+ },
|
|
|
+ submit() {
|
|
|
+ var data = JSON.parse(JSON.stringify(this.formData));
|
|
|
+ this.$http
|
|
|
+ .post({
|
|
|
+ url: this.formData.id ? "/fileInfo/update" : "/fileInfo/save",
|
|
|
+ data: data
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ if (res.success) {
|
|
|
+ this.$message.success("成功");
|
|
|
+ this.$router.go(-1);
|
|
|
+ } else {
|
|
|
+ this.$message.warning("失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ haleSuccess(file) {
|
|
|
+ // console.log(file)
|
|
|
+ file.data.forEach(item => {
|
|
|
+ var nameList = item.split("/");
|
|
|
+ var jsonp = {
|
|
|
+ name: nameList[nameList.length - 1],
|
|
|
+ url: item
|
|
|
+ };
|
|
|
+ this.fileList.splice(0, 1, jsonp);
|
|
|
+ this.formData.url = item;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onDelete() {
|
|
|
+ this.$alert("删除将无法恢复,确认要删除么?", "警告", { type: "error" })
|
|
|
+ .then(() => {
|
|
|
+ return this.$http.post({
|
|
|
+ url: "/fileInfo/del",
|
|
|
+ data: { id: this.formData.id }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ this.$message.success("删除成功");
|
|
|
+ this.$router.go(-1);
|
|
|
+ })
|
|
|
+ .catch(action => {
|
|
|
+ if (action === "cancel") {
|
|
|
+ this.$message.info("删除取消");
|
|
|
+ } else {
|
|
|
+ this.$message.error("删除失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ }
|
|
|
+};
|
|
|
</script>
|
|
|
<style lang="less" scoped>
|
|
|
</style>
|