找回密码
 立即注册

QQ登录

只需一步,快速开始

zjk

中级会员

67

主题

234

帖子

625

积分

中级会员

积分
625
zjk
中级会员   /  发表于:2022-5-30 17:10  /   查看:3424  /  回复:20
1金币
模板js(sgrz.js)

Reporter.vue

  1. <template>
  2.   <j-modal
  3.     :title="title"
  4.     :width="width"
  5.     :visible="visible"
  6.     switchFullscreen
  7.     @ok="handleOk"
  8.     :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
  9.     @cancel="handleCancel"
  10.     cancelText="关闭">
  11.     <div id="report"></div>
  12.   </j-modal>
  13. </template>

  14. <script>
  15.   import "@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css";
  16.   import '@grapecity/spread-sheets-vue';
  17.   import GC from "@grapecity/spread-sheets";
  18.   import '@grapecity/spread-sheets-charts';
  19.   import "@grapecity/spread-sheets-resources-zh";
  20.   import "@grapecity/spread-sheets-barcode";

  21.   GC.Spread.Common.CultureManager.culture("zh-cn");
  22.   GC.Spread.Sheets.LicenseKey='xxxxx';


  23.     export default {
  24.       name: "reporter",
  25.       data(){
  26.         return {
  27.           dataurl:'', //请求后的数据
  28.           path:'', // 模板路径
  29.           title:'',
  30.           width:896,
  31.           visible: false,
  32.           disableSubmit: false
  33.         };
  34.       }, //请求后封装的数据

  35.       /*----------------初始化工作簿----------------*/
  36.       methods:{
  37.         workbookInitialized() {
  38.           var spread = new GC.Spread.Sheets.Workbook(document.getElementById("report"));
  39.           spread.fromJSON(this.path);
  40.           // this.spread.options.tabStripRatio = 0.7;
  41.           var sheet = spread.getActiveSheet();
  42.           this.dataurl='';
  43.           var source = new GC.Spread.Sheets.Bindings.CellBindingSource(this.dataurl);
  44.           sheet.setDataSource(source);
  45.         },
  46.         show(){
  47.           this.visible = true
  48.         },
  49.         close () {
  50.           this.$emit('close');
  51.           this.visible = false;
  52.         },
  53.         handleOk () {
  54.           this.close()
  55.         },
  56.         // submitCallback(){
  57.         //   this.$emit('ok');
  58.         //   this.visible = false;
  59.         // },
  60.         handleCancel () {
  61.           this.close()
  62.         }

  63.       },

  64.       // mounted(){
  65.       //   this.workbookInitialized();
  66.       // }

  67.     }
  68. </script>

  69. <style scoped>

  70. </style>
复制代码
报表列表
  1. <template>
  2.   <a-card :bordered="false">
  3.     <!-- 查询区域 -->
  4.     <div class="table-page-search-wrapper">
  5.       <a-form layout="inline" @keyup.enter.native="searchQuery">
  6.         <a-row :gutter="24">
  7.         </a-row>
  8.       </a-form>
  9.     </div>
  10.     <!-- 查询区域-END -->

  11.     <!-- 操作按钮区域 -->
  12.     <div class="table-operator">
  13.       <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
  14.       <!--//@TODO 报表功能待实现-->
  15.       <a-button @click="showreport(selectionRows)" type="primary">报表</a-button>

  16.       <a-button type="primary" icon="download" @click="handleExportXls('施工日志')">导出</a-button>
  17.       <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
  18.         <a-button type="primary" icon="import">导入</a-button>
  19.       </a-upload>
  20.       <!-- 高级查询区域 -->
  21.       <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
  22.       <a-dropdown v-if="selectedRowKeys.length > 0">
  23.         <a-menu slot="overlay">
  24.           <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
  25.         </a-menu>
  26.         <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
  27.       </a-dropdown>
  28.     </div>

  29.     <!-- table区域-begin -->
  30.     <div>
  31.       <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
  32.         <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
  33.         <a style="margin-left: 24px" @click="onClearSelected">清空</a>
  34.       </div>

  35.       <a-table
  36.         ref="table"
  37.         size="middle"
  38.         :scroll="{x:true}"
  39.         bordered
  40.         rowKey="id"
  41.         :columns="columns"
  42.         :dataSource="dataSource"
  43.         :pagination="ipagination"
  44.         :loading="loading"
  45.         :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
  46.         class="j-table-force-nowrap"
  47.         @change="handleTableChange">

  48.         <template slot="htmlSlot" slot-scope="text">
  49.           <div v-html="text"></div>
  50.         </template>
  51.         <template slot="imgSlot" slot-scope="text">
  52.           <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
  53.           <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
  54.         </template>
  55.         <template slot="fileSlot" slot-scope="text">
  56.           <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
  57.           <a-button
  58.             v-else
  59.             :ghost="true"
  60.             type="primary"
  61.             icon="download"
  62.             size="small"
  63.             @click="downloadFile(text)">
  64.             下载
  65.           </a-button>
  66.         </template>

  67.         <span slot="action" slot-scope="text, record">
  68.           <a @click="handleEdit(record)">编辑</a>

  69.           <a-divider type="vertical" />
  70.           <a-dropdown>
  71.             <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
  72.             <a-menu slot="overlay">
  73.               <a-menu-item>
  74.                 <a @click="handleDetail(record)">详情</a>
  75.               </a-menu-item>
  76.               <a-menu-item>
  77.                 <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
  78.                   <a>删除</a>
  79.                 </a-popconfirm>
  80.               </a-menu-item>
  81.             </a-menu>
  82.           </a-dropdown>
  83.         </span>

  84.       </a-table>
  85.     </div>

  86.     <construction-log-modal ref="modalForm" @ok="modalFormOk"></construction-log-modal>

  87.       <reporter ref="gpreporter"></reporter>

  88.   </a-card>
  89. </template>

  90. <script>

  91.   import '@/assets/less/TableExpand.less'
  92.   import { mixinDevice } from '@/utils/mixin'
  93.   import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  94.   import ConstructionLogModal from './modules/ConstructionLogModal'
  95.   import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  96.   import {getAction} from "../../api/manage";
  97.   import Reporter from './modules/Reporter'

  98.   export default {
  99.     name: 'ConstructionLogList',
  100.     mixins:[JeecgListMixin, mixinDevice],
  101.     components: {
  102.       ConstructionLogModal,
  103.       Reporter
  104.     },
  105.     data () {
  106.       return {
  107.         description: '施工日志管理页面',
  108.         // 表头
  109.         columns: [
  110.         {
  111.             title: '#',
  112.             dataIndex: '',
  113.             key:'rowIndex',
  114.             width:60,
  115.             align:"center",
  116.             customRender:function (t,r,index) {
  117.               return parseInt(index)+1;
  118.             }
  119.           },
  120.           {
  121.             title:'单位',
  122.             align:"center",
  123.             dataIndex: 'unit'
  124.           },
  125.           {
  126.             title:'日期',
  127.             align:"center",
  128.             dataIndex: 'time',
  129.             customRender:function (text) {
  130.               return !text?"":(text.length>10?text.substr(0,10):text)
  131.             }
  132.           },
  133.           {
  134.             title:'星期',
  135.             align:"center",
  136.             dataIndex: 'week_dictText'
  137.           },
  138.           {
  139.             title:'天气',
  140.             align:"center",
  141.             dataIndex: 'weather'
  142.           },
  143.          /* {
  144.             title:'最高气温(℃)',
  145.             align:"center",
  146.             dataIndex: 'tmax'
  147.           },
  148.           {
  149.             title:'最低气温(℃)',
  150.             align:"center",
  151.             dataIndex: 'tmin'
  152.           },*/
  153.           {
  154.             title:'养护航道',
  155.             align:"center",
  156.             dataIndex: 'yhhd'
  157.           },
  158.           {
  159.             title:'桩号',
  160.             align:"center",
  161.             dataIndex: 'zh'
  162.           },
  163.           {
  164.             title:'施工人数',
  165.             align:"center",
  166.             dataIndex: 'sgrs'
  167.           },
  168.           {
  169.             title:'施工班组',
  170.             align:"center",
  171.             dataIndex: 'sgbz'
  172.           },
  173.           /*{
  174.             title:'养护内容',
  175.             align:"center",
  176.             dataIndex: 'content'
  177.           },
  178.           {
  179.             title:'养护情况(包括质量、安全)',
  180.             align:"center",
  181.             dataIndex: 'situation'
  182.           },
  183.           {
  184.             title:'完成后情况',
  185.             align:"center",
  186.             dataIndex: 'situationFinish'
  187.           },*/
  188.           {
  189.             title:'负责人',
  190.             align:"center",
  191.             dataIndex: 'chargePerson'
  192.           },
  193.           {
  194.             title:'记录',
  195.             align:"center",
  196.             dataIndex: 'recorder'
  197.           },
  198.           {
  199.             title: '操作',
  200.             dataIndex: 'action',
  201.             align:"center",
  202.             fixed:"right",
  203.             width:147,
  204.             scopedSlots: { customRender: 'action' }
  205.           }
  206.         ],
  207.         url: {
  208.           // report:"/report/constructionLog/report",
  209.           list: "/report/constructionLog/list",
  210.           delete: "/report/constructionLog/delete",
  211.           deleteBatch: "/report/constructionLog/deleteBatch",
  212.           exportXlsUrl: "/report/constructionLog/exportXls",
  213.           importExcelUrl: "report/constructionLog/importExcel",
  214.          
  215.         },
  216.         path:"./modules/sgrz.js",
  217.         dictOptions:{},
  218.         superFieldList:[],
  219.       }
  220.     },



  221.     created() {
  222.     this.getSuperFieldList();
  223.     },
  224.     computed: {
  225.       importExcelUrl: function(){
  226.         return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
  227.       },
  228.     },
  229.     methods: {
  230.       initDictConfig(){
  231.       },
  232.       //@TODO 获取选中行的数据
  233.       getSelectdata(row){

  234.         return Selecteddata

  235.       },
  236.       //@TODO 报表功能待实现
  237.       showreport(record){
  238.         console.log(record)
  239.         // data=getAction(this.url.report,)
  240.         this.$refs.gpreporter.path=this.path;
  241.         this.$refs.gpreporter.dataurl=record;//改成所选id
  242.         this.$refs.gpreporter.workbookInitialized();
  243.         this.$refs.gpreporter.show();

  244.       },
  245.       getSuperFieldList(){
  246.         let fieldList=[];
  247.         fieldList.push({type:'string',value:'unit',text:'单位',dictCode:''})
  248.         fieldList.push({type:'date',value:'time',text:'日期'})
  249.         fieldList.push({type:'string',value:'week',text:'星期',dictCode:'week'})
  250.         fieldList.push({type:'string',value:'weather',text:'天气',dictCode:''})
  251.         fieldList.push({type:'double',value:'tmax',text:'最高气温(℃)',dictCode:''})
  252.         fieldList.push({type:'double',value:'tmin',text:'最低气温(℃)',dictCode:''})
  253.         fieldList.push({type:'string',value:'yhhd',text:'养护航道',dictCode:''})
  254.         fieldList.push({type:'string',value:'zh',text:'桩号',dictCode:''})
  255.         fieldList.push({type:'int',value:'sgrs',text:'施工人数',dictCode:''})
  256.         fieldList.push({type:'string',value:'sgbz',text:'施工班组',dictCode:''})
  257.         fieldList.push({type:'string',value:'content',text:'养护内容',dictCode:''})
  258.         fieldList.push({type:'string',value:'situation',text:'养护情况(包括质量、安全)',dictCode:''})
  259.         fieldList.push({type:'string',value:'situationFinish',text:'完成后情况',dictCode:''})
  260.         fieldList.push({type:'string',value:'chargePerson',text:'负责人',dictCode:''})
  261.         fieldList.push({type:'string',value:'recorder',text:'记录',dictCode:''})
  262.         this.superFieldList = fieldList
  263.       }
  264.     }
  265.   }
  266. </script>
  267. <style scoped>
  268.   @import '~@assets/less/common.less';
  269. </style>
复制代码
加载的record
image.png303453063.png

点击报表后,加载出来的界面不出现spread

sgrz.js

41.96 KB, 下载次数: 46

最佳答案

查看完整内容

请参考这个最新的demo去调,在调用workbookInitialized的时候需要传参,否则再次调用之后上面定义的workbookInitialized接不到参数就会找不到spread对象。

20 个回复

倒序浏览
最佳答案
最佳答案
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2022-5-30 17:10:35
来自 19#
zjk 发表于 2022-6-1 10:56
虽然还是报fromJSON的错

请参考这个最新的demo去调,在调用workbookInitialized的时候需要传参,否则再次调用之后上面定义的workbookInitialized接不到参数就会找不到spread对象。
image.png690534362.png

init_excel_original.zip

161.6 KB, 下载次数: 32

回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2022-5-30 17:33:19
2#
你好,这边测试了提供的表单,表单是正常的,附件是我测试的demo,点击"绑定数据源"即可看到绑定效果。出现”加载不出来spread报表界面“可能是其他原因造成,但但从上面提供的代码这边无法复现,请移除多余的业务逻辑。直接通过上传附件的方式提供一个可直接运行的demo。这边来调查原因。

init_excel_update.zip

161.23 KB, 下载次数: 38

回复 使用道具 举报
zjk
中级会员   /  发表于:2022-5-31 10:35:37
3#
Derrick.Jiao 发表于 2022-5-30 17:33
你好,这边测试了提供的表单,表单是正常的,附件是我测试的demo,点击"绑定数据源"即可看到绑定效果。出现 ...

我这个是界面初始化不出来,并不是数据没关联上。我看你们都是用<div>套</gc-spread-sheets>套</gc-worksheet>,而我这边是采用的一个div,然后自己用一个方法,去new的
  1. <template>
  2.   <j-modal
  3.     :title="title"
  4.     :width="width"
  5.     :visible="visible"
  6.     switchFullscreen
  7.     @ok="handleOk"
  8.     :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
  9.     @cancel="handleCancel"
  10.     cancelText="关闭">
  11.     <div id="spread"></div>
  12.   </j-modal>
  13. </template>

  14. <script>

  15.   import "@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"
  16.   import '@grapecity/spread-sheets-vue'
  17.   import * as GC from "@grapecity/spread-sheets"
  18.   import * as ExcelIO from "@grapecity/spread-excelio"
  19.   import '@grapecity/spread-sheets-charts'
  20.   import "@grapecity/spread-sheets-resources-zh"
  21.   import "@grapecity/spread-sheets-barcode"
  22.   import "@grapecity/spread-sheets-barcode"
  23.   import '@grapecity/spread-sheets-print'
  24.   GC.Spread.Common.CultureManager.culture("zh-cn");
  25.   GC.Spread.Sheets.LicenseKey=ExcelIO.LicenseKey='mykeys';


  26.     export default{
  27.       name:'Reporter',
  28.       data(){
  29.         return {
  30.           dataurl:'', //请求后的数据
  31.           path:'', // 模板路径
  32.           title:'',
  33.           width:900,
  34.           visible: false,
  35.           disableSubmit: false
  36.         }
  37.       },//请求后封装的数据

  38.       /*----------------初始化工作簿----------------*/

  39.       methods:{
  40.         workbookInitialize(){
  41.           var spread=new GC.Spread.Sheets.Workbook(document.getElementById("spread"));
  42.           spread.fromJSON(this.path)
  43.           // this.spread.options.tabStripRatio = 0.7;
  44.           var sheet = spread.getActiveSheet();
  45.           var source = new GC.Spread.Sheets.Bindings.CellBindingSource(this.dataurl);
  46.           sheet.setDataSource(source);
  47.         },

  48.         show(){
  49.           this.visible = true
  50.           this.workbookInitialize()
  51.         },
  52.         close () {
  53.           this.$emit('close');
  54.           this.visible = false;
  55.         },
  56.         handleOk () {
  57.           this.close()
  58.         },
  59.         // submitCallback(){
  60.         //   this.$emit('ok');
  61.         //   this.visible = false;
  62.         // },
  63.         handleCancel () {
  64.           this.close()
  65.         }

  66.       }
  67.   }

  68.       // mounted(){
  69.       //   this.workbookInitialized();
  70.       // }

  71. </script>
复制代码
回复 使用道具 举报
zjk
中级会员   /  发表于:2022-5-31 10:42:21
4#
zjk 发表于 2022-5-31 10:35
我这个是界面初始化不出来,并不是数据没关联上。我看你们都是用套套,而我这边是采用的一个div,然后自 ...

引用界面
  1. <template>

  2.     <div class="table-operator">
  3.           <!--//@TODO 报表功能待实现-->
  4.       <a-button @click="showreport(selectionRows)" type="primary">报表</a-button>
  5.     </div>
复制代码
回复 使用道具 举报
zjk
中级会员   /  发表于:2022-5-31 11:39:10
5#

image.png884920959.png
image.png864406738.png
现在是将标签改为
image.png296051024.png ,然后用你们的方法初始模板,然后数据无法加载到模板里去,首先是没加下标无法加载,现在在数组里加了下标,还是加载不进来
数据:
image.png561527404.png
而且还一直报fromJSON的出报警
image.png489078063.png
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2022-5-31 12:26:49
6#
zjk 发表于 2022-5-31 11:39
现在是将标签改为
,然后用你们的方法初始模板,然后数据无法加载到模板里去,首先是没加下标无法加 ...

出现上面的报错是因为初始化不正确,导致找不到spread对象,因此也就找不到spread下的fromJSON方法。两个建议:1、使用我们封装好的的标签,就像前面提供的demo那样;2、如果仍是需要使用原生的方式去初始化,可以参考附件的demo。

另外,若上述方案仍未解决你的问题,请移除其余的业务逻辑,提供一个可直接运行的demo,我们这边直接在这个demo上调试,处理效率会更高。光提供截图以及代码片段,这边无法进行复现。

init_excel_update.zip

161.23 KB, 下载次数: 40

回复 使用道具 举报
zjk
中级会员   /  发表于:2022-5-31 14:50:59
7#

15.0.2 vue用SPREADfromJSON BAO

Derrick.Jiao 发表于 2022-5-31 12:26
出现上面的报错是因为初始化不正确,导致找不到spread对象,因此也就找不到spread下的fromJSON方法。两个 ...


viewdemo.zip

6.7 KB, 下载次数: 34

回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2022-5-31 15:27:50
8#

老哥,请提供一个可直接运行的demo吧,我这只能从提供的代码片段去猜是猜不到准确原因的。

在你提供的附件中,这个path我没看到哪里可以传过来
image.png52387999.png

然后在父页面中,我只看到定义了一个按钮,按钮中也使用了子页面的一个方法,这个方法我也没看出来是从哪里给到父页面的
image.png256351927.png

上面都是vue的用法上的问题,也有可能是我对vue理解的不正确。

另外,还有一个最直观的办法就是在你的代码中加上这句console把spread对象打印一下,如果返回的是undefined,说明你的spread对象就没有获取对。
image.png921931152.png

建议可以看下我们如何在vue中引入SpreadJS的教程。
https://www.bilibili.com/video/B ... id_from=333.999.0.0

最后,最最最关键的是,还是建议你提供一个可运行的demo,请勿再提供代码片段,这样问题还是无法得到解决。

回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2022-5-31 15:34:47
9#
另外,凭借我对上面提供附件的理解,我做了一个demo
image.png559080199.png

可以再看下,点击按钮即可弹出Spread。

init_excel_original_update.zip

161.62 KB, 下载次数: 46

回复 使用道具 举报
123下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部