app-todo-list.vue 5.4 KB
Newer Older
1 2
<template>
    <div class='app-todo-list'>
3
        <i-input v-model="query" search enter-button @on-search="handleSearch" class='app-todo-list__search' placeHolder="标题"/>
4
        <el-table :data="myTasks" :border="true" @sort-change="handleSortChange">
5 6 7 8 9 10 11 12 13 14 15 16
            <el-table-column prop="" sortable label="标题">
                <template slot-scope="scope">
                    <span class="title" @click="handleClick(scope.row)">{{ scope.row.description }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="processDefinitionName" sortable label="流程" width="200">
            </el-table-column>
            <el-table-column prop="name" sortable label="状态" width="200">
            </el-table-column>
            <el-table-column prop="createTime" sortable label="创建时间" width="200">
            </el-table-column>
        </el-table>
17 18 19 20 21 22 23 24 25 26
        <el-pagination
            class="app-todo-list__pagination"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="curPage"
            :page-sizes="[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]"
            :page-size="limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
27 28 29 30
    </div>
</template>

<script lang = 'ts'>
31
import AppCenterService from '@/service/app/app-center-service';
32
import { Http } from '@/utils';
33
import { Subscription } from 'rxjs';
34 35 36 37 38 39 40 41 42 43 44
import { Component, Vue } from 'vue-property-decorator';

@Component({
})
export default class AppTodoList extends Vue {

    /**
     * 待办数据
     */
    public myTasks: any[] = [];

45 46 47 48 49 50 51 52 53 54 55 56 57
    /**
     * 查询数据
     */
    public query: string = '';

    /**
     * 分页条数
     */
    public limit: number = 20;

    /**
     * 当前分页
     */
58
    public curPage: number = 1;
59 60 61 62 63 64

    /**
     * 总条数
     */
    public total: number = 0;

65 66 67 68
    /**
     * 排序字段
     */
    public sort: string = '';
69 70 71 72 73 74 75 76
    
    /**
     * 应用状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
     */
    public appStateEvent: Subscription | undefined;
77

78 79 80 81 82
    /**
     * vue创建
     */
    created(): void {
        this.getMyTasks();
83 84 85 86 87 88 89 90 91 92
        if(AppCenterService && AppCenterService.getMessageCenter()){
            this.appStateEvent = AppCenterService.getMessageCenter().subscribe(({ name, action, data }) =>{
                if(!Object.is(name,"srfwftodo")){
                    return;
                }
                if(Object.is(action,'appRefresh')){
                    this.getMyTasks();
                }
            })
        }
93 94 95 96 97 98
    }

    /**
     * 获取待办列表
     */
    public getMyTasks() {
99 100
        const params = {
            size: this.limit,
101
            page: this.curPage - 1
102
        };
103
        let url: any = '/wfcore/mytasks';
104 105 106
        if (this.query) {
            Object.assign(params, {query: this.query});
        }
107 108 109
        if (this.sort) {
            Object.assign(params, {sort: this.sort});
        }
110
        Http.getInstance().get(url, params).then((response: any) => {
111
            if (response && response.status == 200) {
112 113 114 115
                if(response.headers['x-total']){
                    this.total = Number(response.headers['x-total']);
                }
                const data: any = response.data || [];
116 117 118 119 120 121 122
                if (data && data.length > 0) {
                    this.myTasks = data;
                } else {
                    this.myTasks = [];
                }
            }
        }).catch((error: any) => {
123 124
            const message = error.message ? error.message : '加载数据错误';
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: message });
125 126 127 128 129 130 131 132
        })
    }


    /**
     * 处理点击
     */
    public handleClick(data: any) {
133 134 135 136 137 138 139 140
        if(!data || !data.processDefinitionKey || !data.processInstanceBusinessKey || !data.taskDefinitionKey){
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: '参数不足,跳转失败' });
            return;
        }
        const srfappde = (data.processDefinitionKey as string).split('-')[1];
        const url = `/appwfdataredirectview?srfappde=${srfappde};srfappkey=${data.processInstanceBusinessKey};userTaskId=${data.taskDefinitionKey}`;
        const indexPath = this.$viewTool.getIndexRoutePath(this.$route);
        this.$router.push({ path: `${indexPath}${url}` });
141 142
    }

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
    /**
     * 处理搜索
     */
    public handleSearch() {
        this.getMyTasks();
    }

    /**
     * 处理分页数改变
     */
    public handleSizeChange(size: number) {
        this.limit = size;
        this.getMyTasks();
    }

    /**
     * 处理分页改变
     */
    public handleCurrentChange(page: number) {
        this.curPage = page;
        this.getMyTasks();
    }

166 167 168 169 170 171 172 173 174 175
    /**
     * 处理排序改变
     */
    public handleSortChange($event: any) {
        const { prop, order } = $event;
        const dir = Object.is(order, 'ascending') ? 'asc' : Object.is(order, 'descending') ? 'desc' : '';
        this.sort = `${prop},${dir}`;
        this.getMyTasks();
    }

176 177 178 179 180 181 182 183 184 185 186
    /**
     * 组件销毁
     *
     * @memberof MainBase
     */
     public destroyed() {
        if(this.appStateEvent){
            this.appStateEvent.unsubscribe();
        }
    }

187 188 189 190 191 192
}
</script>

<style lang="less">
@import './app-todo-list.less';
</style>