Browse Source

打印权限

ymy 1 năm trước cách đây
mục cha
commit
5217cc7b27

+ 25 - 0
src/api/print.ts

@@ -0,0 +1,25 @@
+import request from '@/benyun/utils/request'
+
+//打印
+export function print(data:any){
+	return request({
+		url: '/print/render',
+		method: 'POST',
+    data:data,
+    headers:{
+      'Print-User':'admin'
+    }
+	})
+}
+
+//打印预览
+export function preview(data:any){
+	return request({
+		url: '/print/preview',
+		method: 'POST',
+    data:data,
+    headers:{
+      'Print-User':'admin'
+    }
+	})
+}

+ 46 - 0
src/api/printPermission.ts

@@ -0,0 +1,46 @@
+import request from '@/benyun/utils/request'
+
+//查询
+export function query(data:any){
+	return request({
+		url: '/print/printPermission/page',
+		method: 'GET',
+    params:data,
+    headers:{
+      'Print-User':'admin'
+    }
+	})
+}
+//新增数据
+export function add(data:any){
+  return request({
+		url: '/print/printPermission/save',
+		method: 'POST',
+    data:data,
+    headers:{
+      'Print-User':'admin'
+    }
+	})
+}
+//修改数据
+export function update(data:any){
+  return request({
+		url: '/print/printPermission/update',
+		method: 'POST',
+    data:data,
+    headers:{
+      'Print-User':'admin'
+    }
+	})
+}
+//删除数据
+export function del(data:any){
+  return request({
+		url: '/print/printPermission/delete',
+		method: 'POST',
+    params:data,
+    headers:{
+      'Print-User':'admin'
+    }
+	})
+}

+ 299 - 0
src/views/print/printPermission/index.vue

@@ -0,0 +1,299 @@
+<template>
+  <div class="print-perm">
+    <module-view :propConfig="config" ref="view" v-loading="load" @pagination="pagination" @onRefresh="getList" @resert="queryList" @search="queryList" 
+    @modalHandle="modalHandle" @clickHandle="clickHandle" @detail="detail"/>
+  </div>
+</template>
+<script lang="ts">
+import { Component, Prop, Vue, Watch } from "vue-property-decorator";
+import {query,add,update,del} from '@/api/printPermission'
+@Component({components:{}})
+export default class PrintPermission extends Vue {
+  load=false;
+  isSearch=false
+  timeNum = 0;
+  config:any={
+    attr:{
+      calculateH:true
+    },
+    search:{
+      attr:{
+        size:'small'
+      },
+      columns:[
+        [{
+          span:8,
+          label:'模板名称',
+          prop:'templateName',
+          component:'by-input',
+          compConfig:{
+            attr:{
+              clearable:true
+            }
+          }
+        },{
+          span:8,
+          label:'模板引擎',
+          prop:'templateEngine',
+          component:'by-select',
+          compConfig:{
+            attr:{
+              clearable:true,
+              data:[{
+                label:'freemarker',
+                value:'freemarker'
+              },{
+                label:'thymeleaf',
+                value:'thymeleaf'
+              }]
+            }
+          }
+        }]
+      ]
+    },
+    tool:{
+      tools:{
+        search:true,
+        refresh:true,
+        add:true,
+        delete:true
+      }
+    },
+    table:{
+      attr:{
+        size:'mini',
+        seq:true,
+        checkbox:true
+      },
+      columns:[{
+        title:'外部用户标识',
+        isDetail:true,
+        field:'userId'
+      },{
+        title:'角色',
+        field:'role',
+        width:130,
+      },{
+        title:'自定义权限',
+        field:'customPermission',
+        width:130
+      },{
+        title:'自定义打印次数限制',
+        field:'customLimit',
+        width:130
+      },{
+        title:'创建时间',
+        field:'createTime',
+        width:140
+      },{
+        title:'操作',
+        action:true,
+        width:100,
+        plugins:[{
+          name:'删除',
+          event:{
+            click:(item:any) => {
+            
+            }
+          }
+        }]
+      }]
+    },
+    modal:{
+      tool:{
+        tools:{
+          return:true,
+          add:true
+        },
+      },
+      form:{
+        attr:{
+          size:'small',
+          width:'900px',
+          labelWidth:'150px',
+          rules:{
+            templateName:[
+              { required: true, message: '模版名称不能为空!', trigger: 'blur' }
+            ],
+          }
+        },
+        columns:[
+          [{
+            label:'外部用户标识',
+            prop:'userId',
+            component:'by-input',
+            compConfig:{
+              attr:{
+                clearable:true
+              }
+            }
+          }],
+          [{
+            label:'角色',
+            prop:'role',
+            component:'by-select',
+            compConfig:{
+              attr:{
+                clearable:true,
+                data:[{
+                  label:'超级管理员',
+                  value:'admin'
+                },{
+                  label:'操作用户',
+                  value:'oper_user'
+                },{
+                  label:'打印用户',
+                  value:'print_user'
+                },{
+                  label:'自定义用户',
+                  value:'custom_user'
+                }]
+              }
+            }
+          }],
+          [{
+            label:'自定义权限',
+            prop:'customPermission',
+            component:'by-input',
+            compConfig:{
+              attr:{
+                clearable:true
+              }
+            }
+          }],
+          [{
+            label:'自定义打印次数限制',
+            prop:'customLimit',
+            component:'by-input',
+            compConfig:{
+              attr:{
+                clearable:true,
+                type:'integer'
+              }
+            }
+          }]
+        ]
+      }
+    }
+  }
+  mounted(){
+    this.$nextTick(()=>{
+      this.getList()
+    })
+  }
+  //分页
+  pagination(){
+    if(this.isSearch){
+      this.queryList();
+    }else{
+      this.getList()
+    }
+  }
+  //列表请求(只有分页,不包含搜素条件)
+  getList(){
+    if(!this.$refs.view){
+      if(this.timeNum > 5){
+        return
+      }
+      setTimeout(()=>{
+        this.getList()
+      },500) 
+      this.timeNum ++;
+      return
+    }
+    this.isSearch = false;
+    let data = (this.$refs.view as any).getPage();
+    delete data.total;
+    this.requestList(data);
+  }
+  //列表请求(包含分页和搜素条件)
+  queryList(){
+    this.isSearch = true;
+    let data = (this.$refs.view as any).getQuery();
+    delete data.total;
+    this.requestList(data);
+  }
+  requestList(data:any){
+    this.load = true;
+    query(data).then((res:any) => {
+      this.load = false;
+      (this.$refs.view as any).setTableValue(res.data.records);
+      let page = {
+        pageNo: res.data.current, //当前页
+        pageSize: res.data.size, //每页条数
+        total: res.data.total //总条数
+      };
+      (this.$refs.view as any).setPage(page)
+
+    }).catch(()=>{
+      this.load = false;
+    })
+  }
+  modalHandle(n:string){
+    if(n == 'onAdd'){
+      (this.$refs.view as any).getFormValidate(this.onAdd)
+    }
+
+    if(n == 'onSave'){
+      (this.$refs.view as any).getFormValidate(this.onSave)
+    }
+  }
+  //新增
+  onAdd(){
+    let value = (this.$refs.view as any).getFormValue();
+    if(value){
+      this.load = true;
+      add(value).then((res:any)=>{
+        this.load = false;
+        this.$message({
+          message:res.msg,
+          type:'success'
+        });
+        (this.$refs.view as any).closeModal();
+        this.getList();
+      }).catch(()=>{
+        this.load = false;
+      })
+    }
+  }
+  //保存
+  onSave(){
+    let data = (this.$refs.view as any).getFormValue();
+    this.load = true;
+    update(data).then((res:any) => {
+      this.$message({
+        message:res.msg,
+        type:'success'
+      });
+      this.load = false;
+      (this.$refs.view as any).closeModal();
+      this.pagination();
+    }).catch(()=>{
+      this.load = false;
+    })
+  }
+  clickHandle(n:string){
+    if(n == 'onAdd'){
+      this.config.modal.tool.tools.add = true;
+      delete this.config.modal.tool.tools.save;
+      (this.$refs.view as any).initFormTool();
+    }
+    if(n == 'onDelete'){
+      
+    }
+  }
+  //点击详情
+  detail(){
+    this.config.modal.tool.tools.save = true;
+    delete this.config.modal.tool.tools.add;
+    (this.$refs.view as any).initFormTool();
+  }
+}
+</script>
+<style lang="scss" scoped>
+.print-perm{
+  height: 100%;
+  width: 100%;
+  overflow-y: hidden;
+}
+</style>

+ 48 - 4
src/views/print/printTemplate/index.vue

@@ -8,6 +8,7 @@
 <script lang="ts">
 import { Component, Prop, Vue, Watch } from "vue-property-decorator";
 import {query,add,update,del} from '@/api/printTemplate'
+import {preview} from '@/api/print'
 @Component({components:{}})
 export default class PrintTemplate extends Vue {
   load=false;
@@ -63,7 +64,8 @@ export default class PrintTemplate extends Vue {
     table:{
       attr:{
         size:'mini',
-        seq:true
+        seq:true,
+        checkbox:true
       },
       columns:[{
         title:'模板名称',
@@ -100,7 +102,16 @@ export default class PrintTemplate extends Vue {
         tools:{
           return:true,
           add:true
-        }
+        },
+        customTools:[{
+          name: '预览', 
+          icon: 'el-icon-view', 
+          event:{
+            click:() => {
+              this.preView()
+            }
+          }
+        }]
       },
       form:{
         attr:{
@@ -185,7 +196,8 @@ export default class PrintTemplate extends Vue {
             compConfig:{
               attr:{
                 defaultValue:'{}',
-                type:'textarea'
+                type:'textarea',
+                rows:3
               }
             }
           }]
@@ -198,9 +210,37 @@ export default class PrintTemplate extends Vue {
       this.getList()
     })
   }
+  //预览
+  preView(){
+    let data = (this.$refs.view as any).getFormValue();
+    if(!data.templateEngine){
+      this.$message('模版引擎不能为空!')
+      return
+    }
+    if(!data.templateHtml){
+      this.$message('模版内容不能为空!')
+      return
+    }
+    if(!data.dataExample){
+      this.$message('示例数据不能为空!')
+      return
+    }
+    this.load=true;
+    preview({
+      templateEngine:data.templateEngine,
+      templateHtml:data.templateHtml,
+      templateData:data.dataExample,
+      outType:'PDF'
+    }).then((res:any) => {
+      this.load=false;
+
+    }).catch((err:any)=>{
+      this.load=false;
+    })
+  }
+  //单个删除
   singleDel(item:any){
     let data=[item.id];
-    console.log(data);
     this.$confirm('此操作将永久删除“'+item.templateName+'”, 是否继续?', '提示', {
       confirmButtonText: '确定',
       cancelButtonText: '取消',
@@ -209,6 +249,7 @@ export default class PrintTemplate extends Vue {
       this.del(data);
     }).catch(() => {});
   }
+  //多个删除
   multipleDel(){
     let data = (this.$refs.view as any).getSelectData();
     if(data.length == 0){
@@ -269,6 +310,7 @@ export default class PrintTemplate extends Vue {
     }
     this.isSearch = false;
     let data = (this.$refs.view as any).getPage();
+    delete data.total;
     this.requestList(data);
   }
   //列表请求(包含分页和搜素条件)
@@ -303,6 +345,7 @@ export default class PrintTemplate extends Vue {
       (this.$refs.view as any).getFormValidate(this.onSave)
     }
   }
+  //新增
   onAdd(){
     let value = (this.$refs.view as any).getFormValue();
     if(value){
@@ -320,6 +363,7 @@ export default class PrintTemplate extends Vue {
       })
     }
   }
+  //保存
   onSave(){
     let data = (this.$refs.view as any).getFormValue();
     this.load = true;