no message
This commit is contained in:
parent
14bb9bb7b2
commit
3ecb3b3992
@ -15,6 +15,22 @@ use Request;
|
||||
*/
|
||||
class FileController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* 获取文件列表
|
||||
*
|
||||
* @apiParam {Number} [pid] 父级ID
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
$user = User::auth();
|
||||
//
|
||||
$pid = intval(Request::input('pid'));
|
||||
//
|
||||
$list = File::whereUserid($user->userid)->wherePid($pid)->orderBy('name')->take(500)->get();
|
||||
//
|
||||
return Base::retSuccess('success', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目
|
||||
*
|
||||
@ -46,10 +62,13 @@ class FileController extends AbstractController
|
||||
}
|
||||
//
|
||||
if ($pid > 0) {
|
||||
if (!File::whereUserid($user->id)->whereId($pid)->exists()) {
|
||||
if (!File::whereUserid($user->userid)->whereId($pid)->exists()) {
|
||||
return Base::retError('参数错误');
|
||||
}
|
||||
}
|
||||
if (File::whereUserid($user->userid)->wherePid($pid)->count() >= 300) {
|
||||
return Base::retError('每个文件夹里最多只能创建300个文件或文件夹');
|
||||
}
|
||||
// 开始创建
|
||||
$file = File::createInstance([
|
||||
'pid' => $pid,
|
||||
|
@ -3,7 +3,7 @@
|
||||
<PageTitle :title="$L('文件')"/>
|
||||
<div class="file-wrapper">
|
||||
<div class="file-head">
|
||||
<h1>{{$L('文件')}}</h1>
|
||||
<h1 @click="pid=0">{{$L('文件')}}</h1>
|
||||
<div class="file-search">
|
||||
<i class="iconfont"></i>
|
||||
</div>
|
||||
@ -21,13 +21,13 @@
|
||||
</EDropdown>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="files.length + temps.length == 0" class="file-no">
|
||||
<div v-if="files.length == 0" class="file-no">
|
||||
<i class="iconfont"></i>
|
||||
<p>{{$L('没有任何文件')}}</p>
|
||||
</div>
|
||||
<div v-else class="file-list">
|
||||
<ul class="clearfix">
|
||||
<li v-for="item in folderList" :class="item.type">
|
||||
<li v-for="item in folderList" :class="item.type" @click="openFile(item)">
|
||||
<div class="file-icon"></div>
|
||||
<div v-if="item._edit" class="file-input">
|
||||
<Input
|
||||
@ -41,7 +41,7 @@
|
||||
</div>
|
||||
<div v-else class="file-name">{{item.name}}</div>
|
||||
</li>
|
||||
<li v-for="item in fileList" :class="item.type">
|
||||
<li v-for="item in fileList" :class="item.type" @click="openFile(item)">
|
||||
<div class="file-icon"></div>
|
||||
<div v-if="item._edit" class="file-input">
|
||||
<Input
|
||||
@ -62,10 +62,14 @@
|
||||
|
||||
<script>
|
||||
import {mapState} from "vuex";
|
||||
import {sortBy} from "lodash";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
loadIng: 0,
|
||||
pid: 0,
|
||||
|
||||
types: [
|
||||
{value: 'folder', name: "目录"},
|
||||
{value: 'document', name: "文本"},
|
||||
@ -74,7 +78,6 @@ export default {
|
||||
{value: 'flow', name: "流程图"},
|
||||
],
|
||||
files: [],
|
||||
temps: [],
|
||||
}
|
||||
},
|
||||
|
||||
@ -90,27 +93,63 @@ export default {
|
||||
...mapState(['userInfo']),
|
||||
|
||||
folderList() {
|
||||
const data = this.files.filter(({type}) => type == 'folder')
|
||||
return Object.assign(data, this.temps.filter(({type}) => type == 'folder'))
|
||||
return sortBy(this.files.filter(({type, pid}) => pid == this.pid && type == 'folder'), 'name')
|
||||
},
|
||||
|
||||
fileList() {
|
||||
const data = this.files.filter(({type}) => type != 'folder')
|
||||
return Object.assign(data, this.temps.filter(({type}) => type != 'folder'))
|
||||
return sortBy(this.files.filter(({type, pid}) => pid == this.pid && type != 'folder'), 'name')
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
|
||||
pid: {
|
||||
handler() {
|
||||
this.getLists();
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
getLists() {
|
||||
this.loadIng++;
|
||||
this.$store.dispatch("call", {
|
||||
url: 'file/lists',
|
||||
data: {
|
||||
pid: this.pid,
|
||||
},
|
||||
}).then(({data}) => {
|
||||
this.loadIng--;
|
||||
this.saveFile(data);
|
||||
}).catch(({msg}) => {
|
||||
$A.modalError(msg);
|
||||
this.loadIng--;
|
||||
})
|
||||
},
|
||||
|
||||
saveFile(file) {
|
||||
if ($A.isArray(file)) {
|
||||
file.forEach((item) => {
|
||||
this.saveFile(item);
|
||||
});
|
||||
return;
|
||||
}
|
||||
let index = this.files.findIndex(({id}) => id == file.id);
|
||||
if (index > -1) {
|
||||
this.files.splice(index, 1, file);
|
||||
} else {
|
||||
this.files.push(file)
|
||||
}
|
||||
},
|
||||
|
||||
addFile(command) {
|
||||
let id = $A.randomString(8);
|
||||
this.temps.push({
|
||||
this.files.push({
|
||||
_edit: true,
|
||||
pid: this.pid,
|
||||
id: id,
|
||||
type: command,
|
||||
name: '',
|
||||
newname: this.$L('未命名')
|
||||
});
|
||||
this.$nextTick(() => {
|
||||
@ -120,21 +159,30 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
openFile(item) {
|
||||
if (item.type == 'folder') {
|
||||
this.pid = item.id;
|
||||
}
|
||||
},
|
||||
|
||||
onBlur(item) {
|
||||
this.onEnter(item);
|
||||
if (!item.newname) {
|
||||
this.files = this.files.filter(({id}) => id != item.id);
|
||||
}
|
||||
},
|
||||
|
||||
onEnter(item) {
|
||||
if (item._load) {
|
||||
return;
|
||||
}
|
||||
if (!item.newname) {
|
||||
this.temps = this.temps.filter(({id}) => id != item.id);
|
||||
this.files = this.files.filter(({id}) => id != item.id);
|
||||
} else {
|
||||
if (item._load) {
|
||||
return;
|
||||
}
|
||||
this.$set(item, '_load', true);
|
||||
this.$store.dispatch("call", {
|
||||
url: 'file/add',
|
||||
data: {
|
||||
pid: item.pid,
|
||||
name: item.newname,
|
||||
type: item.type,
|
||||
},
|
||||
@ -142,18 +190,12 @@ export default {
|
||||
$A.messageSuccess(msg)
|
||||
this.$set(item, '_load', false);
|
||||
this.$set(item, '_edit', false);
|
||||
if (this.temps.find(({id}) => id == item.id)) {
|
||||
this.temps = this.temps.filter(({id}) => id != item.id);
|
||||
this.files.push(data);
|
||||
} else {
|
||||
Object.keys(data).forEach((key) => {
|
||||
this.$set(item, key, data[key]);
|
||||
})
|
||||
}
|
||||
this.files = this.files.filter(({id}) => id != item.id);
|
||||
this.saveFile(data);
|
||||
}).catch(({msg}) => {
|
||||
$A.modalError(msg)
|
||||
this.$set(item, '_edit', false);
|
||||
this.temps = this.temps.filter(({id}) => id != item.id);
|
||||
this.files = this.files.filter(({id}) => id != item.id);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user