123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986 |
- <template>
- <div class="cqcy-content" style="margin: 0;height: calc(100% - 70px);">
- <breadcrumb-view :breadcrumbList="breadcrumbList" :show-index="false"></breadcrumb-view>
- <div v-if="btnType === ''" class="cy-nav-sx">
- <el-select v-model="searchValue"
- style="width: 180px;"
- placeholder="请选择报表类型"
- @change="changeReportTypeEvent">
- <el-option v-for="item in reportOptions"
- style="margin-left: 5px; width: 180px;"
- :key="item.value"
- :label="item.label"
- :value="item.value">
- </el-option>
- </el-select>
- <el-input placeholder="请输入报表名称"
- v-model="searchTxt"
- style="margin-left: 5px; width: 180px;"
- prefix-icon="el-icon-search">
- </el-input>
- <el-button style="margin-left: 5px;" @click="searchReportEvent">查询</el-button>
- </div>
- <!-- <el-button v-if="btnType === ''" type="primary" class="cy-nav-btn" icon="el-icon-circle-plus-outline"-->
- <!-- size="mini" @click="addReportEvent">新增</el-button>-->
- <!-- <el-button v-if="btnType === ''" type="success" class="cy-nav-btn" icon="el-icon-refresh"-->
- <!-- size="mini" @click="refreshReportEvent">刷新</el-button>-->
- <el-divider></el-divider>
- <div class="cy-main">
- <div class="cy-main-left" v-if="!showMainView">
- <div class="cy-list">
- <el-table v-if="reportDataList.length > 0"
- :data="reportDataList"
- border
- :stripe="true"
- :header-cell-style="{background: '#E8E8E8'}"
- @sort-change="sortChange"
- style="width: 100%;">
- <el-table-column
- align="center"
- sortable="custom"
- label="报表名称"
- prop="reportTableName">
- <template slot-scope="scope">
- <span style="color: #409EFF; cursor: pointer;"
- @click="handleReportNodeClick(scope.row, scope.row.userId != uid ? 'deny' : '')"
- :title="scope.row.reportTableName">{{ scope.row.reportTableName }}</span>
- </template>
- </el-table-column>
- <el-table-column
- align="center"
- label="报表状态"
- prop="isAutoReport"
- width="350">
- <template slot-scope="scope">
- <el-tag v-if="scope.row.userId != uid" type="success" style="margin-right: 5px;">被分享</el-tag>
- <el-tag v-if="uid == scope.row.userId && scope.row.userGroupList && scope.row.userGroupList.length > 0"
- type="warning" style="margin-right: 5px;">已分享</el-tag>
- <el-tag v-if="scope.row.isAutoReport == 0" style="margin-right: 5px;">手动报表</el-tag>
- <el-tag v-if="scope.row.isAutoReport == 1" style="margin-right: 5px;">自动报表</el-tag>
- <el-tag v-if="scope.row.isAutoReport == 3" style="margin-right: 5px;">事件驱动报表</el-tag>
- <!-- <el-tag v-if="scope.row.isAutoReport == 0" type="info" style="margin-right: 5px;">默认</el-tag>-->
- </template>
- </el-table-column>
- <!-- <el-table-column-->
- <!-- align="center"-->
- <!-- label="自动报表"-->
- <!-- prop="isAutoReport"-->
- <!-- width="150">-->
- <!-- <template slot-scope="scope">-->
- <!-- <el-switch v-if="scope.row.isAutoReport == '2'" :value="true" active-color="#13ce66"-->
- <!-- disabled></el-switch>-->
- <!-- <el-switch v-else :value="scope.row.isAutoReport == '1'" active-color="#13ce66"-->
- <!-- @change="switchChangeEvent($event, scope.row)" :disabled="uid != scope.row.userId"></el-switch>-->
- <!-- </template>-->
- <!-- </el-table-column>-->
- <el-table-column
- align="center"
- label="当前版本"
- sortable="custom"
- prop="version"
- width="120">
- </el-table-column>
- <el-table-column
- align="center"
- label="创建时间"
- sortable
- prop="createTime"
- width="200">
- </el-table-column>
- <!-- <el-table-column label="操作" align="center" width="300">-->
- <!-- <template slot-scope="scope">-->
- <!-- <el-button type="text"-->
- <!-- v-if="uid == scope.row.userId"-->
- <!-- size="small"-->
- <!-- icon="el-icon-edit"-->
- <!-- @click="editReportItem(scope.row)">修改名称</el-button>-->
- <!-- <el-button type="text"-->
- <!-- v-if="uid == scope.row.userId"-->
- <!-- size="small"-->
- <!-- icon="el-icon-user"-->
- <!-- @click="setUserGroupEvent(scope.row)">授权</el-button>-->
- <!-- <el-button type="text"-->
- <!-- v-if="uid == scope.row.userId"-->
- <!-- size="small"-->
- <!-- icon="el-icon-delete"-->
- <!-- style="color: red;"-->
- <!-- @click="removeReportItem(scope.row)">删除</el-button>-->
- <!-- </template>-->
- <!-- </el-table-column>-->
- </el-table>
- <el-empty v-else description="暂无数据"></el-empty>
- </div>
- <el-pagination
- background
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- :current-page="reportPage"
- :page-size="reportLimit"
- layout="sizes, prev, pager, next, total"
- :total="reportTotal">
- </el-pagination>
- </div>
- <div class="cy-main-right" :style="showMainView ? '' : 'display: none;'">
- <el-row v-if="btnType == 'add'" style="margin: 10px 20px;">
- <el-button type="primary" size="mini" icon="el-icon-document" @click="saveReportInfo">保存报表</el-button>
- <el-button type="danger" size="mini" icon="el-icon-circle-close" @click="cancelSaveReport">取消</el-button>
- </el-row>
- <el-row v-if="btnType == 'show'" style="margin: 10px 20px;">
- <!-- <el-button type="success" size="mini" icon="el-icon-document-checked" @click="updateReport">保存</el-button>-->
- <el-button type="primary" size="mini" icon="el-icon-download" @click="downloadReport">下载</el-button>
- <el-button type="warning" size="mini" icon="el-icon-printer" @click="printExcel">打印</el-button>
- <el-button type="info" size="mini" icon="el-icon-document" @click="historyReport">运行记录</el-button>
- <el-button type="danger" size="mini" icon="el-icon-circle-close" @click="cancelSaveReport">关闭</el-button>
- </el-row>
- <el-row v-if="btnType == 'showShared'" style="margin: 10px 20px;">
- <el-button type="primary" size="mini" icon="el-icon-download" @click="downloadReport">下载</el-button>
- <el-button type="warning" size="mini" icon="el-icon-printer" @click="printExcel">打印</el-button>
- <el-button type="info" size="mini" icon="el-icon-document" @click="historyReport">运行记录</el-button>
- <el-button type="danger" size="mini" icon="el-icon-circle-close" @click="cancelSaveReport">关闭</el-button>
- </el-row>
- <el-row v-if="btnType == 'showChild'" style="margin: 10px 20px;">
- <el-button type="primary" size="mini" icon="el-icon-download" @click="downloadReport">下载</el-button>
- <el-button type="warning" size="mini" icon="el-icon-printer" @click="printExcel">打印</el-button>
- <el-button type="danger" size="mini" icon="el-icon-circle-close" @click="cancelSaveReport2">关闭</el-button>
- </el-row>
- <div id="luckysheet"
- style="margin:0px;padding:0px;position:relative;height:calc(100% - 50px);width:100%;left: 20px;top: 0px;bottom:0px;">
- </div>
- </div>
- </div>
- <!-- 新增报表 -->
- <el-dialog
- title="新增报表"
- width="50%"
- top="10vh"
- center
- :before-close="dialogClose"
- :visible.sync="dialogReportTemplateVisible"
- :close-on-click-modal="false"
- :append-to-body="true">
- <el-form ref="reportForm" :model="reportForm" :rules="reportRules" label-width="80px">
- <el-form-item label="报表模板" prop="reportTemplate">
- <el-select v-model="reportForm.reportTemplate" filterable placeholder="请选择报表模板" style="width: 100%;">
- <el-option
- v-for="item in reportTemplateList"
- :key="item.id"
- :label="item.templateName"
- :value="item.id">
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="取值方式" prop="reportValueFormat">
- <el-radio v-model="reportForm.reportValueFormat" label="0">时段数据</el-radio>
- </el-form-item>
- <el-form-item label="数据时间" prop="reportDate">
- <el-date-picker
- v-model="reportForm.reportDate" :editable="false" :clearable="false"
- style="width: 100%;"
- type="datetimerange"
- :picker-options="{
- format: 'yyyy-MM-dd HH:mm:ss'
- }"
- value-format="yyyy-MM-dd HH:mm:ss"
- range-separator="至"
- start-placeholder="开始日期"
- end-placeholder="结束日期">
- </el-date-picker>
- </el-form-item>
- <el-form-item style="text-align: center;">
- <el-button type="primary" @click="chooseReportEvent" style="margin-top: 20px;">确定</el-button>
- <el-button @click="dialogClose" style="margin-top: 20px;">取消</el-button>
- </el-form-item>
- </el-form>
- </el-dialog>
- <!-- 用户组选择 -->
- <el-dialog
- title="选择用户组"
- width="840px"
- top="10vh"
- center
- :before-close="dialogClose"
- :visible.sync="dialogUserGroupVisible"
- :close-on-click-modal="false"
- :append-to-body="true">
- <!-- <el-form label-width="80px">-->
- <!-- <el-form-item label="用户组">-->
- <!-- <el-select v-model="userGroupInfo" filterable clearable multiple placeholder="请选择用户组" style="width: 100%;">-->
- <!-- <el-option-->
- <!-- v-for="item in userGroupList"-->
- <!-- :key="item.id"-->
- <!-- :label="item.userGroupName"-->
- <!-- :value="item.id">-->
- <!-- </el-option>-->
- <!-- </el-select>-->
- <!-- </el-form-item>-->
- <!-- </el-form>-->
- <div class="ug-div">
- <el-transfer
- v-model="userGroupInfo"
- :titles="['用户组列表', '已选择用户组']"
- :data="userGroupList"
- :props="{
- key: 'id',
- label: 'userGroupName'
- }">
- </el-transfer>
- </div>
- <span slot='footer'>
- <el-button type="primary" @click="chooseUserGroupEvent" style="margin-top: 20px;">确定</el-button>
- <el-button @click="dialogClose" style="margin-top: 20px;">取消</el-button>
- </span>
- </el-dialog>
- <!-- 自动报表CRON定时表达式 -->
- <el-dialog
- title="配置定时任务"
- width="50%"
- top="10vh"
- center
- :before-close="dialogClose"
- :visible.sync="dialogAutoReportVisible"
- :close-on-click-modal="false"
- :append-to-body="true">
- <el-form label-width="80px">
- <el-radio-group v-model="radioByCron">
- <el-form-item label="秒">
- <el-radio :label="1">
- <span style="margin-right: 10px;">每</span>
- <el-input-number size="mini" v-model="radioByCronValS" :min="1" :max="59"></el-input-number>
- <span style="margin-left: 10px;">秒执行一次</span>
- </el-radio>
- </el-form-item>
- <el-form-item label="分钟">
- <el-radio :label="2">
- <span style="margin-right: 10px;">每</span>
- <el-input-number size="mini" v-model="radioByCronValM" :min="1" :max="59"></el-input-number>
- <span style="margin-left: 10px;">分钟执行一次</span>
- </el-radio>
- </el-form-item>
- <el-form-item label="小时">
- <el-radio :label="3">
- <span style="margin-right: 10px;">每</span>
- <el-input-number size="mini" v-model="radioByCronValH" :min="1" :max="2"></el-input-number>
- <span style="margin-left: 10px;">小时执行一次</span>
- </el-radio>
- </el-form-item>
- <el-form-item label="指定时间">
- <el-radio :label="4">
- <span style="margin-right: 10px;">在每天的</span>
- <el-time-picker v-model="radioByCronValD"
- size="mini"
- placeholder="请选择时间"
- :clearable="false"
- :editable="false"
- value-format="HH:mm:ss"
- :picker-options="{
- format: 'HH:mm:ss'
- }">
- </el-time-picker>
- <span style="margin-left: 10px;">执行一次</span>
- </el-radio>
- </el-form-item>
- <el-form-item label="">
- <el-radio :label="5">
- <span style="margin-right: 10px;">在每月</span>
- <el-input-number size="mini" v-model="radioByCronValMo" :min="1" :max="31"></el-input-number>
- <span style="margin-right: 10px; margin-left: 10px;">号的</span>
- <el-time-picker v-model="radioByCronValMoD"
- size="mini"
- placeholder="请选择时间"
- :clearable="false"
- :editable="false"
- value-format="HH:mm:ss"
- :picker-options="{
- format: 'HH:mm:ss'
- }">
- </el-time-picker>
- <span style="margin-left: 10px;">执行一次</span>
- </el-radio>
- </el-form-item>
- </el-radio-group>
- <!-- <el-form-item label="表达式">-->
- <!-- <el-input type="text" placeholder="请输入定时任务表达式" v-model="cronVal" maxlength="50"></el-input>-->
- <!-- </el-form-item>-->
- <!-- <div>-->
- <!-- <label>常用定时任务表达式例子</label>-->
- <!-- <ul>-->
- <!-- <li v-for="(item, i) in cronList" style="margin-bottom: 5px;">-->
- <!-- <span class="cron-txt" @click="cronNodeEvent(item)">{{ item.value }}</span>-->
- <!-- <span class="cron-txt-desc">{{ item.label }}</span>-->
- <!-- </li>-->
- <!-- </ul>-->
- <!-- </div>-->
- </el-form>
- <span slot='footer'>
- <el-button type="primary" @click="chooseCronEvent">确定</el-button>
- <el-button @click="dialogClose">取消</el-button>
- </span>
- </el-dialog>
- <!-- 报表下载类型选择 -->
- <el-dialog
- title="选择下载类型"
- width="500px"
- center
- :before-close="dialogClose"
- :visible.sync="dialogDownloadReportTypeVisible"
- :close-on-click-modal="false"
- :append-to-body="true">
- <div style="text-align: center;">
- <el-radio v-model="downloadType" label="1">Excel</el-radio>
- <el-radio v-model="downloadType" label="2" disabled>PDF</el-radio>
- </div>
- <div style="text-align: center; margin-top: 40px;">
- <el-button type="primary" @click="downloadReportEvent">确定</el-button>
- </div>
- </el-dialog>
- <!-- 历史报表查看 -->
- <el-dialog
- title="运行报表记录"
- width="80%"
- top="10vh"
- center
- :before-close="dialogClose"
- :visible.sync="dialogHistoryReportVisible"
- :close-on-click-modal="false"
- :append-to-body="true">
- <div style="height: 60vh;">
- <el-table
- :data="reportHistoryData" border :stripe="true"
- :header-cell-style="{background: '#E8E8E8'}"
- @sort-change="sortChange1"
- style="width: 100%; height: calc(100% - 50px); overflow: auto;">
- <el-table-column
- align="center"
- sortable="custom"
- label="报表名称"
- prop="reportTableName">
- <template slot-scope="scope">
- <span style="color: #409EFF; cursor: pointer;"
- @click="handleReportNodeClick(scope.row, 'history')"
- :title="scope.row.reportTableName">{{ scope.row.reportTableName }}</span>
- </template>
- </el-table-column>
- <!-- <el-table-column-->
- <!-- align="center"-->
- <!-- label="报表状态"-->
- <!-- prop="isAutoReport"-->
- <!-- width="180">-->
- <!-- <template slot-scope="scope">-->
- <!-- <el-tag v-if="scope.row.userId != uid" type="success" style="margin-right: 5px;">被分享</el-tag>-->
- <!-- <el-tag v-if="uid == scope.row.userId && scope.row.userGroupList && scope.row.userGroupList.length > 0"-->
- <!-- type="warning" style="margin-right: 5px;">已分享</el-tag>-->
- <!-- </template>-->
- <!-- </el-table-column>-->
- <el-table-column
- align="center"
- label="当前版本"
- sortable="custom"
- prop="version"
- width="120">
- </el-table-column>
- <el-table-column
- align="center"
- label="运行时间"
- sortable
- prop="createTime"
- width="200">
- </el-table-column>
- <!-- <el-table-column label="操作" align="center" width="300">-->
- <!-- <template slot-scope="scope">-->
- <!-- <el-button type="text"-->
- <!-- v-if="uid == scope.row.userId"-->
- <!-- size="small"-->
- <!-- icon="el-icon-delete"-->
- <!-- style="color: red;"-->
- <!-- @click="removeReportItem(scope.row, 'record')">删除</el-button>-->
- <!-- </template>-->
- <!-- </el-table-column>-->
- </el-table>
- <el-pagination
- style="margin-top: 20px;"
- background
- layout="sizes, prev, pager, next, total"
- :current-page="reportHistoryPage"
- :page-size="reportHistoryLimit"
- @size-change="sizeHistoryChangeEvent"
- @current-change="currentHistoryChangeEvent"
- :total="reportHistoryTotal">
- </el-pagination>
- </div>
- </el-dialog>
- <div id="print-area" style="display: none;position: absolute;z-index: 0;top: 0;width: 100%;height: 100vh;overflow: hidden;">
- <div id="print-html" ref="printPayFeeNew"></div>
- </div>
- </div>
- </template>
- <script>
- import BreadcrumbView from '@/components/BreadcrumbView'
- import {customCompare, getNowFormatDate, showAlertWin, showLoading} from '@/utils/cqcy'
- import {
- delReportTableById,
- getAllDataModel, getAllOkReportTable,
- getAllTableTemplate, getAutoChReportTable, getChartData,
- getDataModelById, getReportTableById, getTableData,
- getTableTemplateById, saveReport, tableAssignUserById, tableExchangeTypeById, updateReportTable, updateTableNameById
- } from '@/api/datasource'
- import Print from 'print-js'
- import {getUsername} from '@/utils/auth'
- import {exportExcel} from '@/utils/export'
- import {getAllUserGroup} from "@/api/user";
- import {mapGetters} from "vuex";
- import {insertLuckysheetEChart} from "@/utils/luckysheettool";
- export default {
- name: "index",
- components: {
- BreadcrumbView
- },
- computed: {
- ...mapGetters([
- 'name',
- 'uid'
- ])
- },
- data() {
- return {
- breadcrumbList: ['我的报表'],
- groupProps: {
- isLeaf: 'leaf'
- },
- showMainView: false,
- chooseMyReport: null,
- dialogReportTemplateVisible: false,
- dialogDownloadReportTypeVisible: false,
- dialogAutoReportVisible: false,
- dialogUserGroupVisible: false,
- dialogHistoryReportVisible: false,
- downloadType: '1',
- btnType: '',
- hasUserGroup: false,
- userGroupInfo: null,
- userGroupList: [],
- radioByCron: null,
- radioByCronValS: '',
- radioByCronValM: '',
- radioByCronValH: '',
- radioByCronValD: null,
- radioByCronValMo: '',
- radioByCronValMoD: null,
- cronVal: '',
- cronList: [],
- reportId: null,
- reportTemplateList: [],
- dataModelList: [],
- chooseReportTemplate: null,
- chooseReportTemplateId: null,
- delFlag: 0,
- reportForm: {
- reportTemplate: null,
- reportValueFormat: '0',
- reportDate: [getNowFormatDate('yyyy-MM-dd') + ' 09:00:00',
- getNowFormatDate('yyyy-MM-dd') + ' 18:00:00']
- },
- searchValue: null,
- searchTxt: '',
- reportOptions: [{
- label: '所有报表',
- value: -1
- }, {
- label: '手动报表',
- value: 0
- }, {
- label: '自动报表',
- value: 1
- }, {
- label: '事件驱动报表',
- value: 3
- }],
- reportHistoryData: [],
- reportHistoryTotal: 0,
- reportHistoryPage: 1,
- reportHistoryLimit: 10,
- reportTotal: 0,
- reportPage: 1,
- reportLimit: 10,
- reportDataList: [],
- reportRules: {
- reportTemplate: [
- {required: true, message: '请选择报表模板', trigger: 'change'}
- ],
- reportValueFormat: [
- {required: true, message: '请选择取值方式', trigger: 'change'}
- ],
- reportDate: [
- {required: true, message: '请选择数据时间'}
- ]
- },
- luckysheetOption: {
- container: 'luckysheet', // 设定 DOM 容器的 id
- title: '报表模板', // 设定表格名称
- lang: 'zh', // 设定表格语言
- showinfobar: false, // 是否显示顶部信息栏
- showtoolbar: false, // 是否显示工具栏
- showtoolbarConfig: {
- paintFormat: true, //格式刷
- moreFormats: true, // 单元格格式
- font: true, // 字体
- fontSize: true, // 字号大小
- bold: true, // 粗体 (Ctrl+B)
- italic: true, // 斜体 (Ctrl+I)
- strikethrough: true, // 删除线 (Alt+Shift+5)
- underline: true, // 下划线 (Alt+Shift+6)
- textColor: true, // 文本颜色
- fillColor: true, // 单元格颜色
- border: true, // 边框
- mergeCell: true, // 合并单元格
- horizontalAlignMode: true, // 水平对齐方式
- verticalAlignMode: true, // 垂直对齐方式
- function: true, // 公式
- // image: true
- // chart: true
- },
- showsheetbar: false, // 是否显示底部 sheet 页按钮
- sheetFormulaBar: false, // 是否显示公式
- row: 100, // 是否显示底部 sheet 页按钮
- data: [{
- "name": "统计报表", //工作表名称
- }],
- cellRightClickConfig: { // 自定义配置单元格右击菜单
- copy: true, // 复制
- copyAs: false, // 复制为
- paste: true, // 粘贴
- insertRow: true, // 插入行
- insertColumn: true, // 插入列
- deleteRow: true, // 删除选中行
- deleteColumn: true, // 删除选中列
- deleteCell: false, // 删除单元格
- hideRow: false, // 隐藏选中行和显示选中行
- hideColumn: false, // 隐藏选中列和显示选中列
- rowHeight: true, // 行高
- columnWidth: true, // 列宽
- clear: false, // 清除内容
- matrix: false, // 矩阵操作选区
- sort: false, // 排序选区
- filter: false, // 筛选选区
- chart: true, // 图表生成
- image: false, // 插入图片
- link: false, // 插入链接
- data: false, // 数据验证
- cellFormat: false // 设置单元格格式
- },
- plugins: ['chart']
- }
- }
- },
- watch: {},
- beforeDestroy() {
- this.chooseMyReport = null
- },
- created() {
- luckysheet.destroy()
- this.loadReport()
- this.initCronList()
- },
- methods: {
- sortChange({ prop, order }) {
- this.reportDataList.sort(customCompare(prop, order))
- },
- sortChange1({ prop, order }) {
- this.reportHistoryData.sort(customCompare(prop, order))
- },
- handleSizeChange(val) {
- this.reportPage = 1
- this.reportLimit = val
- this.loadReport()
- },
- handleCurrentChange(val) {
- this.reportPage = val
- this.loadReport()
- },
- sizeHistoryChangeEvent(val) {
- this.reportHistoryPage = 1
- this.reportHistoryLimit = val
- this.historyReport()
- },
- currentHistoryChangeEvent(val) {
- this.reportHistoryPage = val
- this.historyReport()
- },
- changeReportTypeEvent(val) {
- this.reportPage = 1
- this.searchValue = val
- this.loadReport()
- },
- searchReportEvent() {
- this.reportPage = 1
- this.loadReport()
- },
- validCron(value) {
- const cronParse = require('cron-parser')
- try {
- const interval = cronParse.parseExpression(value)
- console.log('cronDate:', interval.next().toDate())
- return true
- } catch (e) {
- }
- return false
- },
- analysisCron() {
- if (!this.cronVal) return
- let s = this.cronVal.split(' ')
- if (s[0].indexOf('/') > -1) {
- this.radioByCron = 1
- this.radioByCronValS = s[0].split('/')[1]
- } else if (s[1].indexOf('/') > -1) {
- this.radioByCron = 2
- this.radioByCronValM = s[1].split('/')[1]
- } else if (s[2].indexOf('/') > -1) {
- this.radioByCron = 3
- this.radioByCronValH = s[2].split('/')[1]
- } else if (s[3] === '*') {
- this.radioByCron = 4
- this.radioByCronValD = s[2] + ':' + s[1] + ':' + s[0]
- } else {
- this.radioByCron = 5
- this.radioByCronValMo = s[3]
- this.radioByCronValMoD = s[2] + ':' + s[1] + ':' + s[0]
- }
- },
- getCron() {
- let result = null
- switch (this.radioByCron) {
- // 按每秒执行:0/2 * * * * ?
- case 1:
- if (Number.isInteger(this.radioByCronValS)) {
- result = '0/#{cron} * * * * ?'
- result = result.replace('#{cron}', this.radioByCronValS)
- }
- break
- // 按每分钟执行:0 0/2 * * * ?
- case 2:
- if (Number.isInteger(this.radioByCronValM)) {
- result = '0 0/#{cron} * * * ?'
- result = result.replace('#{cron}', this.radioByCronValM)
- }
- break
- // 按每小时执行:0 0 0/2 * * ?
- case 3:
- if (Number.isInteger(this.radioByCronValH)) {
- result = '0 0 0/#{cron} * * ?'
- result = result.replace('#{cron}', this.radioByCronValH)
- }
- break
- // 每天定时执行:0 15 10 * * ?
- case 4:
- if (this.radioByCronValD) {
- let times = this.radioByCronValD.split(':')
- result = '#{cron1} #{cron2} #{cron3} * * ?'
- result = result.replace('#{cron1}', times[2])
- result = result.replace('#{cron2}', times[1])
- result = result.replace('#{cron3}', times[0])
- result = result.replace(/00/g, '0')
- }
- break
- // 每月定时执行:0 0 2 1 * ?
- case 5:
- if (Number.isInteger(this.radioByCronValMo) && this.radioByCronValMoD) {
- let times = this.radioByCronValMoD.split(':')
- result = '#{cron1} #{cron2} #{cron3} #{cron4} * ?'
- result = result.replace('#{cron1}', times[2])
- result = result.replace('#{cron2}', times[1])
- result = result.replace('#{cron3}', times[0])
- result = result.replace('#{cron4}', this.radioByCronValMo)
- result = result.replace(/00/g, '0')
- }
- break
- default:
- break
- }
- return result
- },
- chooseCronEvent() {
- this.cronVal = this.getCron()
- if (!this.cronVal) {
- this.$message({
- message: '请指定定时任务类型或运行时间!',
- type: 'warning'
- })
- return
- }
- if (!this.validCron(this.cronVal)) {
- this.$message({
- message: '定时任务表达式格式不正确,请检查!',
- type: 'warning'
- })
- return
- }
- const loading = showLoading(this, '请稍候···')
- let params = {
- 'id': this.reportId,
- 'isAutoReport': '1',
- 'cron': this.cronVal
- }
- tableExchangeTypeById(params).then(res => {
- loading.close()
- this.dialogClose()
- this.loadReport()
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- },
- resetRadioVal() {
- this.radioByCron = null
- this.radioByCronValS = ''
- this.radioByCronValM = ''
- this.radioByCronValH = ''
- this.radioByCronValD = null
- this.radioByCronValMo = ''
- this.radioByCronValMoD = null
- this.cronVal = ''
- },
- switchChangeEvent(val, data) {
- if (val) {
- this.resetRadioVal()
- this.dialogAutoReportVisible = true
- this.reportId = data.id
- getReportTableById(data.id).then(res => {
- this.cronVal = res.data.cron
- this.analysisCron()
- }).catch((e) => {
- showAlertWin(this, e)
- })
- return
- }
- const loading = showLoading(this, '请稍候···')
- let params = {
- 'id': data.id,
- 'isAutoReport': '0'
- }
- tableExchangeTypeById(params).then(res => {
- loading.close()
- this.loadReport()
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- },
- /** 新增报表 */
- addReportEvent() {
- this.getAllReportTemplate()
- this.dialogReportTemplateVisible = true
- },
- /** 刷新报表 */
- refreshReportEvent() {
- this.reportPage = 1
- this.loadReport()
- },
- /** 模版报表选择 */
- chooseReportEvent() {
- this.$refs['reportForm'].validate((valid) => {
- if (valid) {
- const loading = showLoading(this, '数据加载中,请稍候···')
- getTableTemplateById(this.reportForm.reportTemplate).then(res => {
- if (!res.data) {
- loading.close()
- this.$message({
- message: '选择的报表模板不存在!',
- type: 'warning'
- })
- return
- }
- this.showMainView = true
- let luckyData = JSON.parse(res.data.templateData)
- this.chooseReportTemplateId = res.data.id
- this.chooseReportTemplate = luckyData
- this.drawLuckyExcel(luckyData, () => {
- loading.close()
- this.btnType = 'add'
- this.$refs.reportForm.resetFields()
- this.dialogReportTemplateVisible = false
- this.breadcrumbList = ['新增报表']
- })
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- }
- })
- },
- /** 根据 ID 查询数据模型 */
- getDataModelById(loading, reportData) {
- if (!loading) {
- loading = showLoading(this, '数据加载中,请稍候···')
- }
- getDataModelById(this.reportForm.operationRule).then(res => {
- loading.close()
- if (!res.data) {
- this.$message({
- message: '选择的四则运算表达式不存在!',
- type: 'warning'
- })
- return
- }
- let luckyData = JSON.parse(reportData.templateData)
- this.drawLuckyExcel(luckyData)
- this.btnType = 'add'
- this.dialogReportTemplateVisible = false
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- },
- /** 绘制 Excel 表 */
- drawLuckyExcel(luckyData, callback) {
- let _this = this
- luckysheet.destroy()
- let option = luckyData.option
- option.data = luckyData.data
- let charts = luckyData.charts
- let tables = luckyData.tables
- option.hook = {
- workbookCreateAfter() {
- for (let i in charts) {
- _this.insertEChartInfo(charts[i])
- }
- for (let i in tables) {
- _this.insertTableInfo(tables[i])
- }
- _this.drawBaseInfo()
- if (callback) {
- callback()
- }
- }
- }
- luckysheet.create(option)
- },
- /** 获取图表数据 */
- getChartData(data, callback) {
- getChartData(data).then(res => {
- if (!res.data) {
- if (callback) callback([])
- return
- }
- if (callback) callback(res.data)
- }).catch((e) => {
- if (callback) callback([])
- showAlertWin(this, e)
- })
- },
- /** 获取表格数据 */
- getTableData(data, callback) {
- getTableData(data).then(res => {
- if (!res.data) {
- if (callback) callback([])
- return
- }
- if (callback) callback(res.data)
- }).catch((e) => {
- if (callback) callback([])
- showAlertWin(this, e)
- })
- },
- /** 向 Excel 插入表格 */
- insertTableInfo(tableData) {
- let params = []
- let itemList = tableData.item
- for (let i in itemList) {
- let temp = itemList[i]
- params.push({
- 'itemGroupId': temp.itemGroupId,
- 'itemName': temp.itemName
- })
- }
- let p = {
- 'reportValueFormat': this.reportForm.reportValueFormat,
- 'tableDataDtoChList': params,
- 'showType': tableData.showType
- }
- if (this.reportForm.reportDate && this.reportForm.reportDate.length > 0) {
- p.startBelongTime = this.reportForm.reportDate[0]
- p.endBelongTime = this.reportForm.reportDate[1]
- } else {
- p.startBelongTime = getNowFormatDate('yyyy-MM-dd') + ' 08:00:00'
- p.endBelongTime = getNowFormatDate('yyyy-MM-dd') + ' 18:00:00'
- }
- this.getTableData(p, (res) => {
- // console.log('option==>', luckysheet.getAllSheets()[0])
- // console.log('table1==>', res)
- // const optionData = packtable(res, luckysheet.getAllSheets()[0])
- // console.log('table2==>', optionData)
- setTimeout(() => {
- this.drawTableData(res, p.showType, luckysheet.getAllSheets()[0])
- }, 500)
- })
- },
- drawBaseInfo() {
- let currDate = getNowFormatDate('yyyy-MM-dd')
- let currDateTime = getNowFormatDate('yyyy-MM-dd HH:mm:ss')
- let option = luckysheet.getAllSheets()[0]
- option.celldata.map(item => {
- if (item.v.v) {
- item.v.v = String(item.v.v).trim();
- if (item.v.v.match(/\${([^}]+)}/g)) { // 替换${xxx}内部数据
- if (item.v.v.indexOf('${currDate}') > -1) {
- let val = item.v.v
- val = val.replace('${currDate}', currDate)
- luckysheet.setCellValue(item.r, item.c, val)
- }
- if (item.v.v.indexOf('${currDateTime}') > -1) {
- let val = item.v.v
- val = val.replace('${currDateTime}', currDateTime)
- luckysheet.setCellValue(item.r, item.c, val)
- }
- if (item.v.v.indexOf('${userName}') > -1) {
- let val = item.v.v
- val = val.replace('${userName}', getUsername())
- luckysheet.setCellValue(item.r, item.c, val)
- }
- if (item.v.v.indexOf('${winUserName}') > -1) {
- let val = item.v.v
- val = val.replace('${winUserName}', process.env.VUE_APP_WINNAME)
- luckysheet.setCellValue(item.r, item.c, val)
- }
- }
- }
- })
- },
- drawTableData(sources, type, option) {
- option.celldata.map(item => {
- if (item.v.v) {
- item.v.v = String(item.v.v).trim();
- if (item.v.v.match(/\${([^}]+)}/g)) { // 替换${xxx}内部数据
- sources.forEach(source => {
- let itemName = source.itemName
- itemName = itemName.substring(itemName.lastIndexOf('.') + 1)
- let name = '${' + source.itemGroupId + '.' + itemName + '.' + type.dataId + '}'
- if (item.v.v === name) {
- let dataList = source.dataList
- // for (let i = 0; i < dataList.length; i++) {
- for (let i = 0; i < type.valLine; i++) {
- let p_r = parseInt(item.r)
- let p_c = parseInt(item.c)
- if (type.valType == '2') p_r += i
- else p_c += i
- luckysheet.setCellValue(p_r, p_c, dataList[i] ? dataList[i] : '')
- }
- }
- })
- }
- }
- })
- },
- /** 向 Excel 插入图表 */
- insertEChartInfo(chart) {
- let _self = this
- console.log(chart)
- let info = chart.info
- let itemList = chart.item
- let itemArr = []
- for (let i in itemList) {
- let temp = itemList[i]
- itemArr.push({
- 'itemGroupId': temp.itemGroupId,
- 'id': temp.id,
- 'itemName': temp.itemName
- })
- }
- let params = {
- 'type': info.option.series[0].type,
- 'chartTimeType': this.reportForm.reportValueFormat,
- 'tableDataDtoChList': itemArr
- }
- if (this.reportForm.reportDate && this.reportForm.reportDate.length > 0) {
- params.startBelongTime = this.reportForm.reportDate[0]
- params.endBelongTime = this.reportForm.reportDate[1]
- } else {
- params.startBelongTime = getNowFormatDate('yyyy-MM-dd') + ' 08:00:00'
- params.endBelongTime = getNowFormatDate('yyyy-MM-dd') + ' 18:00:00'
- }
- this.getChartData(params, (res) => {
- let result = (res instanceof Array) ? res : []
- // 系列
- let series = info.option.series
- for (let i in series) {
- let temp = series[i]
- temp.data = []
- for (let j in result) {
- if (params.type == 'pie') {
- temp.name = result[j].name
- temp.data.push({
- 'name': result[j].describe ? result[j].describe : result[j].name,
- 'value': result[j].value
- })
- } else {
- temp.data = result[i].dataList ? result[i].dataList : []
- }
- }
- }
- if (params.type != 'pie') {
- // x 轴
- let xAxis = info.option.xAxis
- let legend = info.option.legend
- xAxis.data = []
- legend.data = []
- for (let i in result) {
- let name = result[i].describe ? result[i].describe : result[i].itemName
- xAxis.data.push(name)
- legend.data.push(name)
- }
- }
- console.log(params.type, info)
- setTimeout(() => {
- const sheet = luckysheet.getLuckysheetfile()[0]
- let optionData = sheet.data
- try {
- let flag = true
- insertLuckysheetEChart({
- selector: '#luckysheet',
- info,
- sheet,
- optionData,
- echarts,
- luckysheet,
- $,
- _self,
- flag
- })
- } catch (e) {
- console.log(999, e == 'echarts is not defined')
- console.error(e)
- }
- }, 200)
- })
- },
- /** 查询所有报表信息 */
- getAllReportTemplate() {
- const loading = showLoading(this, '数据加载中,请稍候···')
- let params = {
- 'page': 1,
- 'limit': 1000
- }
- getAllTableTemplate(params).then(res => {
- loading.close()
- if (!res.data) {
- return
- }
- this.reportTemplateList = res.data.tableTemplateList
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- },
- /** 查询所有数据模型 */
- getAllDataModel() {
- let params = {
- 'page': 1,
- 'limit': 1000
- }
- getAllDataModel(params).then(res => {
- if (!res.data) {
- return
- }
- this.dataModelList = res.data.dataModelList
- }).catch((e) => {
- showAlertWin(this, e)
- })
- },
- /** 查询我的报表列表 */
- loadReport() {
- const loading = showLoading(this, '加载中,请稍候···')
- let params = {
- 'page': this.reportPage,
- 'limit': this.reportLimit
- }
- if (this.searchValue != '-1') {
- params.isAutoReport = this.searchValue
- }
- if (this.searchTxt && this.searchTxt.trim()) {
- params.reportTableName = this.searchTxt
- }
- // getAllReportTable(params).then(res => {
- getAllOkReportTable(params).then(res => {
- loading.close()
- if (!res || !res.data) {
- return
- }
- this.reportTotal = res.data.count
- this.reportDataList = res.data.reportTableList
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- },
- /** 设置用户组信息 */
- setUserGroupEvent(data) {
- if (data.userId != this.uid) {
- this.$message({
- message: '您没有权限进行设置!',
- type: 'warning'
- })
- return
- }
- this.reportId = data.id
- this.dialogUserGroupVisible = true
- getAllUserGroup().then(res => {
- this.$nextTick(() => {
- this.userGroupList = res.data
- // this.userGroupInfo = data.userGroupList
- this.userGroupInfo = []
- for (let i = 0; i < data.userGroupList.length; i++) {
- this.userGroupInfo.push(data.userGroupList[i].id)
- }
- if (data.userGroupList && data.userGroupList.length > 0) {
- this.hasUserGroup = true
- }
- })
- }).catch((e) => {
- showAlertWin(this, e)
- })
- },
- chooseUserGroupEvent() {
- // if (!this.userGroupInfo) {
- // this.$message({
- // message: '请选择用户组!',
- // type: 'warning'
- // })
- // return
- // }
- let params = {
- 'id': this.reportId,
- 'userGroupList': []
- }
- for (let i = 0; i < this.userGroupInfo.length; i ++) {
- params.userGroupList.push({
- 'id': this.userGroupInfo[i]
- })
- }
- tableAssignUserById(params).then(res => {
- if (this.hasUserGroup || this.userGroupInfo) {
- this.$message({
- message: '保存成功!',
- type: 'success'
- })
- this.hasUserGroup = false
- }
- this.dialogClose()
- this.loadReport()
- }).catch((e) => {
- showAlertWin(this, e)
- })
- },
- /** 处理自动报表数据信息 */
- drawAutoReportData(datas) {
- if (!datas || datas.length == 0) {
- return
- }
- datas.forEach((data) => {
- if (!data || !data.item) {
- return
- }
- let showInfo = data.showType
- let fieldList = data.field
- data.item.forEach((item, i) => {
- if (!item || !item.dataList) {
- return
- }
- let itemName = item.itemName
- itemName = itemName.substring(itemName.lastIndexOf('.') + 1)
- let tempName = '${' + item.itemGroupId + '.' + itemName + '.' + showInfo.dataId + '}'
- let p_r, p_c
- if (fieldList[i] && tempName == fieldList[i].name) {
- p_r = parseInt(fieldList[i].r)
- p_c = parseInt(fieldList[i].c)
- } else {
- for (let n = 0; n < fieldList.length; n ++) {
- if (fieldList[n].name == tempName) {
- p_r = parseInt(fieldList[n].r)
- p_c = parseInt(fieldList[n].c)
- break
- }
- }
- }
- // 数据信息
- let dataList = item.dataList
- for (let j = 0; j < showInfo.valLine; j++) {
- let c = p_c
- let r = p_r
- if (showInfo.valType == '2') r += j
- else c += j
- luckysheet.setCellValue(r, c, dataList[j] ? (dataList[j] + '') : '')
- }
- })
- })
- },
- /** 报表点击事件 */
- handleReportNodeClick(data, type) {
- if (data.id == -1 || this.delFlag == 1) {
- return
- }
- const loading = showLoading(this, '加载中,请稍候···')
- getReportTableById(data.id).then(res => {
- loading.close()
- if (!res.data) {
- this.$message({
- message: '选择的报表不存在!',
- type: 'warning'
- })
- return
- }
- this.showMainView = true
- this.breadcrumbList = [res.data.reportTableName]
- let reportTableData = res.data.reportTableData
- let luckyData = JSON.parse(reportTableData)
- console.log(luckyData)
- // 只读
- if (type === 'history') {
- this.dialogHistoryReportVisible = false
- this.btnType = 'showChild'
- } else if (type === 'deny') {
- this.chooseMyReport = res.data
- this.dialogHistoryReportVisible = false
- this.btnType = 'showShared'
- } else {
- this.chooseMyReport = res.data
- this.btnType = 'show'
- }
- this.setLuckysheetStatus(luckyData, true, type)
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- },
- /** 设置工作表状态 */
- setLuckysheetStatus(luckyData, isReadOnly, type) {
- let _this = this
- luckysheet.destroy()
- let option = luckyData.option
- if (!option) option = JSON.parse(JSON.stringify(this.luckysheetOption))
- option.data = luckyData.data
- if (isReadOnly) {
- // 设置工作表保护
- option.data[0].config.authority = {
- sheet: 1, // 如果为 1 或 true,则该工作表受到保护;如果为 0 或 false,则该工作表不受保护。
- hintText: '该工作表受到保护,无法操作', // 弹窗提示的文字
- }
- // 关闭右键菜单
- option.cellRightClickConfig.chart = false
- option.cellRightClickConfig.columnWidth = false
- option.cellRightClickConfig.rowHeight = false
- option.cellRightClickConfig.deleteColumn = false
- option.cellRightClickConfig.deleteRow = false
- option.cellRightClickConfig.insertColumn = false
- option.cellRightClickConfig.insertRow = false
- // 关闭工具栏
- option.showtoolbar = false
- option.enableAddRow = false
- option.showtoolbarConfig = {
- bold: false,
- border: false,
- fillColor: false,
- font: false,
- fontSize: false,
- function: false,
- horizontalAlignMode: false,
- italic: false,
- mergeCell: false,
- moreFormats: false,
- paintFormat: false,
- strikethrough: false,
- textColor: false,
- underline: false,
- verticalAlignMode: false
- }
- }
- // 钩子函数
- option.hook = {
- workbookCreateAfter() {
- let charts = luckyData.charts
- let tables = luckyData.tables
- option.data.forEach((data, i) => {
- if (data.chart && data.chart.length > 0) {
- data.chart.forEach((chart, j) => {
- console.log(chart.chart_id)
- let dom = document.getElementById(chart.chart_id + '_c')
- if (dom) dom.style.display = 'none'
- })
- }
- })
- if (type == '' || type == 'deny') {
- for (let i in charts) {
- _this.insertEChartInfo(charts[i])
- }
- for (let i in tables) {
- _this.insertTableInfo(tables[i])
- }
- _this.drawBaseInfo()
- }
- _this.drawAutoReportData(tables)
- luckysheet.setRangeShow('BH1')
- }
- }
- luckysheet.create(option)
- },
- /** 修改报表信息 */
- editReportItem(data) {
- this.$prompt('请输入报表名称', '修改报表名称', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- inputValue: data.reportTableName,
- customClass: 'close_confirm',
- closeOnClickModal: false,
- inputValidator: (val) => {
- if (!val || !val.trim()) {
- return '报表名称不能为空'
- }
- if (val.length > 20) {
- return '报表名称必须在20字以内'
- }
- }
- }).then(({value}) => {
- const loading = showLoading(this, '修改中,请稍候···')
- let params = {
- 'id': data.id,
- 'reportTableName': value
- }
- updateTableNameById(params).then(res => {
- loading.close()
- let msg = res.data ? '修改成功!' : '修改失败!'
- let msgType = res.data ? 'success' : 'warning'
- this.$message({
- message: msg,
- type: msgType
- })
- this.reportPage = 1
- this.loadReport()
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- }).catch((e) => {
- console.log(e)
- })
- },
- /** 报表移除 */
- removeReportItem(data, type) {
- this.$confirm('您确定要删除该报表吗?', '温馨提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- customClass: 'close_confirm',
- closeOnClickModal: false
- }).then(() => {
- const loading = showLoading(this, '删除中,请稍候···')
- delReportTableById(data.id).then(res => {
- loading.close()
- let msg = res.data ? '删除成功!' : '删除失败!'
- let msgType = res.data ? 'success' : 'warning'
- this.$message({
- message: msg,
- type: msgType
- })
- if (type == 'record') {
- this.reportHistoryPage = 1
- this.historyReport()
- return
- }
- this.reportPage = 1
- this.loadReport()
- this.cancelSaveReport()
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- }).catch(() => {
- })
- },
- /** 获取单元格大小 */
- getCellSize(celldata, r, c, luckysheet) {
- const { cs, rs } = celldata.data[r][c].mc
- const rowhidden = celldata.config.rowhidden && Object.keys(celldata.config.rowhidden) || ''
- const rowArr = []
- for (let i = 0; i < rs; i++) {
- let rowIndex = r + i
- if (rowhidden.indexOf(String(rowIndex)) < 0) {
- rowArr.push(rowIndex)
- }
- }
- const colArr = []
- for (let j = 0; j < cs; j++) {
- colArr.push(c + j)
- }
- const totalHeight = Object.values(
- luckysheet.getRowHeight(rowArr)
- ).reduce((a, b) => a + b)
- const totalWidth = Object.values(
- luckysheet.getColumnWidth(colArr)
- ).reduce((a, b) => a + b)
- return {
- w: totalWidth,
- h: totalHeight
- }
- },
- /** 获取图片位置 */
- getImagePosition(num, arr) {
- let index = 0
- let minIndex
- let maxIndex
- for (let i = 0; i < arr.length; i++) {
- if (num < arr[i]) {
- index = i
- break
- }
- }
- if (index == 0) {
- minIndex = 0
- maxIndex = 1
- } else if (index == arr.length - 1) {
- minIndex = arr.length - 2
- maxIndex = arr.length - 1
- } else {
- minIndex = index - 1
- maxIndex = index
- }
- let min = arr[minIndex]
- let max = arr[maxIndex]
- let radio = Math.abs((num - min) / (max - min)) + index
- return radio
- },
- /** 图表转换为图片 */
- convertChart(luckyData) {
- const optionData = luckysheet.getLuckysheetfile()[0]
- let {
- visibledatacolumn, // 所有行的位置
- visibledatarow // 所有列的位置
- } = optionData
- // 动态图表
- if (luckyData.charts && luckyData.charts.length > 0) {
- luckyData.charts.forEach((chart, i) => {
- let myChart = echarts.init(
- document.getElementsByClassName(chart.info.className)[0]
- )
- let baseData = myChart.getConnectedDataURL({
- type: 'png',
- pixelRatio: 2,
- backgroundColor: '#ffffff'
- })
- // luckysheet.cancelRangeMerge(chart.info.pos)
- luckysheet.insertImage(baseData, {
- rowIndex: chart.info.pos[0],
- colIndex: chart.info.pos[1],
- cellSize: this.getCellSize(optionData, chart.info.pos[0], chart.info.pos[1], luckysheet),
- success: function () {
- console.log("插入成功")
- }
- })
- })
- }
- // 静态图表
- if (luckyData.data && luckyData.data.length > 0) {
- luckyData.data.forEach((data, i) => {
- if (data.chart && data.chart.length > 0) {
- data.chart.forEach((chart, j) => {
- let myChart = echarts.init(
- document.getElementById(chart.chart_id)
- )
- myChart.setOption(chart.chartOptions);
- let baseData = myChart.getConnectedDataURL({
- type: 'png',
- pixelRatio: 2,
- backgroundColor: '#ffffff'
- })
- let col_st = this.getImagePosition(chart.left, visibledatacolumn)
- let row_st = this.getImagePosition(chart.top, visibledatarow)
- luckysheet.insertImage(baseData, {
- rowIndex: parseInt(row_st),
- colIndex: parseInt(col_st),
- cellSize: {
- w: chart.width,
- h: chart.height,
- },
- success: function () {
- console.log("插入成功")
- }
- })
- })
- }
- })
- }
- },
- /** 处理日期显示数字问题 */
- withDateData(excelData) {
- if (!excelData) {
- return
- }
- excelData.map((item) => {
- if (item) {
- item.map((ll) => {
- if (ll && ll.ct && ll.ct.t && ll.ct.t === 'd') {
- ll.m = ll.m,
- ll.v = ll.m,
- ll.ct = {
- fa: "@",
- t: "s",
- }
- }
- })
- }
- })
- },
- /** 保存报表信息 */
- saveReportInfo() {
- this.$prompt('请输入报表名称', '保存', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- customClass: 'close_confirm',
- closeOnClickModal: false,
- inputValidator: (val) => {
- if (!val) {
- return '报表名称不能为空'
- }
- if (val.length > 20) {
- return '报表名称必须在20字以内'
- }
- }
- }).then(({value}) => {
- if (!this.chooseReportTemplate) {
- this.$message({
- message: '请重新选择报表模板',
- type: 'warning'
- })
- return
- }
- const loading = showLoading(this, '保存中,请稍候···')
- let excelData = this.chooseReportTemplate.data[0].data
- this.withDateData(excelData)
- this.convertChart(this.chooseReportTemplate)
- let data = {
- 'tableTemplateId': this.chooseReportTemplateId,
- 'reportTableName': value,
- 'reportValueFormat': this.reportForm.reportValueFormat,
- 'reportTableData': JSON.stringify(this.chooseReportTemplate)
- }
- saveReport(data).then(res => {
- loading.close()
- let msg = res.data ? '保存成功!' : '保存失败!'
- let msgType = res.data ? 'success' : 'error'
- this.$message({
- message: msg,
- type: msgType
- })
- this.showMainView = false
- this.loadReport()
- this.cancelSaveReport()
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- }).catch((e) => {
- console.log(e)
- })
- },
- /** 更新报表信息 */
- updateReport() {
- console.log(this.chooseMyReport)
- if (!this.chooseMyReport || !this.chooseMyReport.id) {
- this.$message({
- message: '保存失败,请刷新后重试!',
- type: 'warning'
- })
- return
- }
- this.$prompt('请输入报表名称', '保存', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- customClass: 'close_confirm',
- closeOnClickModal: false,
- inputValue: this.chooseMyReport.reportTableName,
- inputValidator: (val) => {
- if (!val) {
- return '报表名称不能为空'
- }
- if (val.length > 20) {
- return '报表名称必须在20字以内'
- }
- }
- }).then(({value}) => {
- const loading = showLoading(this, '保存中,请稍候···')
- let _data = JSON.parse(this.getLuckysheetConfig())
- let _data2 = JSON.parse(this.chooseMyReport.reportTableData)
- let excelData = _data[0].data
- this.withDateData(excelData)
- _data2.data = _data
- this.convertChart(_data2)
- let data = this.chooseMyReport
- data.reportTableName = value
- data.reportTableData = JSON.stringify(_data2)
- updateReportTable(data).then(res => {
- loading.close()
- let msg = res.data ? '保存成功!' : '保存失败!'
- let msgType = res.data ? 'success' : 'error'
- this.$message({
- message: msg,
- type: msgType
- })
- this.showMainView = false
- this.loadReport()
- this.cancelSaveReport()
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- }).catch((e) => {
- console.log(e)
- })
- },
- /** 保存数据格式转换 */
- getLuckysheetConfig() {
- let ls = luckysheet.getLuckysheetfile()
- ls.forEach((item, index) => {
- if(item.chart) {
- item.chart.forEach((chart, i) => {
- ls[index].chart[i] = {
- ...ls[index].chart[i],
- chartOptions: {...chartmix.default.getChartJson(chart.chart_id)}
- }
- let div = document.getElementById(chart.chart_id + '_c');
- if(div.style) {
- ls[index].chart[i].left = parseInt(div.style.left)
- ls[index].chart[i].top = parseInt(div.style.top)
- ls[index].chart[i].width = parseInt(div.style.width)
- ls[index].chart[i].height = parseInt(div.style.height)
- }
- })
- }
- })
- return JSON.stringify(ls)
- },
- /** 报表下载 */
- downloadReport() {
- this.dialogDownloadReportTypeVisible = true
- },
- /** 报表下载事件 */
- downloadReportEvent() {
- if (!this.chooseMyReport) {
- this.$message({
- message: '请选择报表',
- type: 'warning'
- })
- return
- }
- let reportName = this.chooseMyReport.reportTableName ? this.chooseMyReport.reportTableName : '统计报表'
- if (this.downloadType == '1') {
- // exportExcel(luckysheet, reportName, ExcelJS).then((res) => {
- // console.log("result==>", res)
- // // this.$message({
- // // message: res,
- // // type: 'success'
- // // })
- // this.dialogDownloadReportTypeVisible = false
- // }).catch((err) => {
- // })
- exportExcel(luckysheet.getAllSheets(), reportName)
- setTimeout(() => {
- this.dialogDownloadReportTypeVisible = false
- }, 500)
- }
- },
- /** 报表记录 */
- historyReport() {
- const loading = showLoading(this, '加载中,请稍候···')
- let params = {
- 'page': this.reportHistoryPage,
- 'limit': this.reportHistoryLimit,
- 'autoTableId': this.chooseMyReport.id
- }
- getAutoChReportTable(params).then(res => {
- loading.close()
- this.dialogHistoryReportVisible = true
- if (!res.data) return
- this.reportHistoryData = res.data.reportTableList
- this.reportHistoryTotal = res.data.count
- }).catch((e) => {
- loading.close()
- showAlertWin(this, e)
- })
- },
- getPrintSheetArea() {
- const sheetData = luckysheet.getSheetData();
- let objRowColumn = {
- row: [0, 0], //行
- column: [0, 0], //列
- };
- // * item是行、index是行索引、it是一行里的一格、itemIndex是这一格在这一行里的列索引
- sheetData.forEach((item, index) => {
- //行数
- item.forEach((it, itemIndex) => {
- if (it !== null && it.v) {
- console.log(index, it)
- if (objRowColumn.row[1] < index) {
- objRowColumn.row[1] = index; //row第二位
- }
- if (objRowColumn.column[1] < itemIndex) {
- objRowColumn.column[1] = itemIndex; //column第二位
- }
- }
- });
- });
- return objRowColumn;
- },
- /** 打印操作 */
- printExcel() {
- const loading = showLoading(this, '请稍候···')
- document.querySelector('#print-area').style = "display:block";
- window.luckysheet.hideGridLines();
- // 获取当前选中区域
- let currentSelected = luckysheet.getRange()
- // 如果当前选中区只是一个单元格,则认为选取无效。
- if (currentSelected[0] != null
- && (currentSelected[0].row[1] - currentSelected[0].row[0] >= 1
- || currentSelected[0].column[1] - currentSelected[0].column[0] >= 1)) {
- // 生成base64图片
- let imgSrc = luckysheet.getScreenshot();
- window.luckysheet.showGridLines();
- // * Lodop中的ADD_PRINT_IMAGE,也可以直接输出base64码图片,不用加img标签(如果加了img标签,会被当做超文本对待,受浏览器引擎解析的影响)
- let $img = `<img src=${imgSrc} style="max-width: 90%;" />`
- this.$nextTick(() => {
- document.querySelector('#print-html').innerHTML = $img;
- setTimeout(() => {
- Print({
- printable: 'print-html',
- type: 'html',
- documentTitle: '文档标题',
- header: '',
- headerStyle: 'font-weight:400;text-align:center;',
- style: '@page {margin: 0 10mm};', // 不打印页眉和页脚
- honorColor: true, // 是否打印彩色文本
- targetStyles: ['*'] // 允许打印所有样式属性
- }) // Print.js插件
- document.querySelector("#print-area").style.display = "none";
- loading.close()
- }, 1000)
- })
- } else {
- // 获取打印区域的行列
- let RowColumn = this.getPrintSheetArea();
- // 因需要打印左边的边框,需重新设置第一列
- RowColumn.column[0] = 0;
- // 进行选区操作
- luckysheet.setRangeShow(RowColumn);
- let imgSrc = luckysheet.getScreenshot(); // 生成base64图片
- window.luckysheet.showGridLines();
- // * Lodop中的ADD_PRINT_IMAGE,也可以直接输出base64码图片,不用加img标签(如果加了img标签,会被当做超文本对待,受浏览器引擎解析的影响)
- let $img = `<img src=${imgSrc} style="max-width: 90%;" />`
- this.$nextTick(() => {
- document.querySelector('#print-html').innerHTML = $img;
- setTimeout(() => {
- Print({
- printable: 'print-html',
- type: 'html',
- documentTitle: '文档标题',
- header: '',
- headerStyle: 'font-weight:400;text-align:center;',
- style: '@page {margin: 0 10mm};', // 不打印页眉和页脚
- honorColor: true, // 是否打印彩色文本
- targetStyles: ['*'] // 允许打印所有样式属性
- }) // Print.js插件
- document.querySelector("#print-area").style.display = "none";
- loading.close()
- }, 1000)
- })
- }
- },
- /** 自定义选中区域 */
- getExcelRowColumn() {
- const sheetData = luckysheet.getSheetData();
- let objRowColumn = {
- row: [null, null], //行
- column: [null, null], //列
- };
- sheetData.forEach((item, index) => {
- //行数
- item.forEach((it, itemIndex) => {
- console.log(it)
- if (it !== null) {
- if (objRowColumn.row[0] == null) objRowColumn.row[0] = index; // row第一位
- objRowColumn.row[1] = index; //row第二位
- if (objRowColumn.column[0] == null)
- objRowColumn.column[0] = itemIndex; //column第一位
- objRowColumn.column[1] = itemIndex; //column第二位
- }
- });
- });
- return objRowColumn;
- },
- cronNodeEvent(obj) {
- this.cronVal = obj.value
- },
- initCronList() {
- this.cronList = []
- this.cronList.push({ value: '0/2 * * * * ?', label: '表示每2秒钟执行一次任务' })
- this.cronList.push({ value: '0 0/2 * * * ?', label: '表示每2分钟执行一次任务' })
- this.cronList.push({ value: '0 0 0/2 * * ?', label: '表示每2小时执行一次任务' })
- this.cronList.push({ value: '0 15 10 * * ?', label: '表示在每天上午10点15分执行一次任务' })
- this.cronList.push({ value: '0 0 10,14,16 * * ?', label: '表示在每天的上午10点、下午2点、下午4点分别执行一次任务' })
- this.cronList.push({ value: '0 0/30 9-17 * * ?', label: '表示在每天的上午9点到下午5点的范围内每30分钟执行一次任务' })
- this.cronList.push({ value: '0 0 12 ? * WED', label: '表示在每周星期三中午12点执行一次任务' })
- this.cronList.push({ value: '0 0 2 1 * ?', label: '表示在每月的1日的凌晨2点执行一次任务' })
- },
- /** 取消保存报表 */
- cancelSaveReport2() {
- this.handleReportNodeClick(this.chooseMyReport, this.chooseMyReport.userId !== this.uid ? 'deny' : '')
- },
- /** 取消保存报表 */
- cancelSaveReport() {
- luckysheet.destroy()
- this.breadcrumbList = ['我的报表']
- this.showMainView = false
- this.btnType = ''
- this.chooseMyReport = null
- if (this.$refs['reportForm']) this.$refs['reportForm'].resetFields()
- },
- /** 弹出层关闭事件 */
- dialogClose(done) {
- this.cronVal = ''
- this.reportId = null
- // this.userGroupInfo = null
- if (typeof (done) === 'function') {
- done()
- } else {
- this.dialogReportTemplateVisible = false
- this.dialogDownloadReportTypeVisible = false
- this.dialogAutoReportVisible = false
- this.dialogUserGroupVisible = false
- }
- }
- }
- }
- </script>
- <style rel="stylesheet/scss" lang="scss">
- .breadcrumb-content {
- padding-bottom: 0;
- }
- .cy-nav-sx {
- float: left !important;
- margin-top: -23px !important;
- margin-left: 120px !important;
- display: flex;
- }
- .cy-nav-btn {
- float: right !important;
- margin-right: 20px !important;
- margin-top: -20px !important;
- }
- .cy-main {
- margin: 10px 20px;
- width: calc(100% - 40px);
- height: calc(100% - 100px);
- .cy-btn {
- margin-bottom: 10px;
- }
- .cy-btn .el-link {
- margin-right: 15px;
- }
- .cy-main-left {
- width: 100%;
- height: 100%;
- overflow: auto;
- //float: left;
- padding: 5px 10px;
- //border-right: 1px solid #d4d4d4;
- .cy-list {
- overflow: auto;
- height: 100%;
- height: calc(100% - 40px);
- ul {
- display: flex;
- flex-wrap: wrap;
- padding: 0;
- margin-top: 0;
- li {
- list-style-type: none;
- background: #41aed7;
- width: 23%;
- margin: 10px 1%;
- border-radius: 8px;
- height: 110px;
- padding: 15px;
- color: #ffffff;
- .cy-item-name {
- font-size: 14px;
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- margin-bottom: 15px;
- cursor: pointer;
- }
- .cy-item-val {
- font-size: 12px;
- }
- .cy-list-item {
- font-size: 12px;
- color: #f6f6f6;
- width: 100%;
- //display: flex;
- margin-top: 40px;
- }
- }
- }
- }
- }
- .cy-main-right {
- width: 100%;
- height: 100%;
- float: left;
- overflow: hidden;
- }
- }
- .cy-group-tree1 {
- font-size: 14px;
- .custom-tree-node1 {
- height: 28px;
- line-height: 28px;
- }
- }
- .cron-txt {
- color: blue;
- margin-right: 20px;
- cursor: pointer;
- font-weight: bold;
- font-size: 16px;
- }
- .cron-txt-desc {
- }
- .ug-div {
- .el-transfer-panel {
- width: 300px;
- }
- }
- </style>
|