123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476 |
- <!-- eslint-disable vue/no-parsing-error -->
- <template>
- <div
- v-loading="saveLoading"
- class="inner-container"
- :element-loading-text="saveText"
- >
- <el-scrollbar class="data-set-scrollbar">
- <div class="header">
- <el-page-header class="bs-el-page-header">
- <template slot="content">
- <div class="page-header">
- <div class="page-header-left">
- {{ !isEdit ? '自助数据集详情' : dataForm.id ? '自助数据集编辑' : '自助数据集新增' }}
- </div>
- <div class="page-header-right">
- <el-button
- class="bs-el-button-default"
- @click="openNewWindow('https://www.yuque.com/chuinixiongkou/bigscreen/self_dataset')"
- >
- 帮助
- </el-button>
- <el-button
- v-if="isEdit"
- type="primary"
- @click="save('form')"
- >
- 保存
- </el-button>
- <el-button
- class="back bs-el-button-default"
- @click="goBack"
- >
- 返回
- </el-button>
- </div>
- </div>
- </template>
- </el-page-header>
- </div>
- <el-row style="margin: 16px 16px 0;">
- <el-col :span="isEdit ? 16 : 24">
- <el-form
- ref="form"
- :model="dataForm"
- :rules="rules"
- label-width="120px"
- style="padding: 16px 16px 0;"
- >
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item
- label="名称"
- prop="name"
- >
- <el-input
- v-model="dataForm.name"
- class="bs-el-input"
- clearable
- :disabled="!isEdit"
- />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item
- label="分组"
- prop="typeId"
- >
- <el-select
- ref="selectParentName"
- v-model="dataForm.typeId"
- popper-class="bs-el-select"
- class="bs-el-select"
- clearable
- :disabled="!isEdit"
- @clear="clearType"
- @visible-change="setCurrentNode"
- >
- <el-option
- style="height: auto;padding: 0;"
- :label="typeName"
- :value="dataForm.typeId"
- >
- <div>
- <el-tree
- ref="categorySelectTree"
- :data="categoryData"
- node-key="id"
- :indent="0"
- :props="{ label: 'name', children: 'children' }"
- :default-expand-all="true"
- :highlight-current="true"
- :expand-on-click-node="false"
- class="bs-el-tree"
- @node-click="selectParentCategory"
- >
- <span
- slot-scope="{ data }"
- class="custom-tree-node"
- >
- <span>
- <i
- :class="data.children && data.children.length ? 'el-icon el-icon-folder' : 'el-icon el-icon-document'"
- />
- {{ data.name }}
- </span>
- </span>
- </el-tree>
- </div>
- </el-option>
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col :span="12">
- <el-form-item
- label="描述"
- prop="remark"
- >
- <el-input
- v-model="dataForm.remark"
- class="bs-el-input"
- :disabled="!isEdit"
- />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item
- label="数据源"
- prop="sourceId"
- >
- <el-select
- v-model="dataForm.sourceId"
- clearable
- filterable
- class="bs-el-select"
- popper-class="bs-el-select"
- placeholder="请选择数据源"
- :disabled="!isEdit"
- >
- <el-option
- v-for="source in sourceList"
- :key="source.id"
- :label="source.sourceName"
- :value="source.id"
- />
- </el-select>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- <div
- v-if="isEdit"
- class="sql-config"
- >
- <div>
- <codemirror
- ref="targetInSql"
- v-model="dataForm.sqlProcess"
- :options="cOptions"
- style="margin-top: 2px"
- />
- <div class="bs-codemirror-bottom-text">
- 示例:
- <strong><br>
- 1、常规使用 select * from table where table_field = <span style="color: red;">${参数名称}</span><br>
- 2、标签使用
- <el-tooltip
- class="item"
- effect="dark"
- content="<参数名称></参数名称>为非空标签, 当该参数值为空时, 标签部分不进行处理"
- placement="top-start"
- ><i class="el-icon-question" />
- </el-tooltip>
- select * from table where 1=1 <span style="color: blue;"><参数名称></span> and table_field = <span
- style="color: red;"
- >${参数名称}</span> <span style="color: blue;"></参数名称></span>
- </strong>
- </div>
- </div>
- <div style="text-align: center; padding: 16px 0;">
- <el-button
- type="primary"
- @click="buildParamsAndRun"
- >
- 解析并运行
- </el-button>
- </div>
- </div>
- </el-col>
- <el-col
- v-if="isEdit"
- :span="8"
- >
- <div class="right-setting">
- <div class="paramConfig">
- <div class="title-style bs-title-style">
- SQL参数
- <el-button
- type="text"
- style="float: right;border: none;margin-top: -4px;"
- @click="openParamsConfig"
- >
- 配置
- </el-button>
- </div>
- <div class="field-wrap bs-field-wrap bs-scrollbar">
- <div
- v-for="param in dataForm.paramsList"
- :key="param.name"
- class="field-item"
- @click="openParamsConfig"
- >
- <span>{{ param.name }}</span> <span
- v-show="param.remark"
- style="color: #909399;"
- >({{ param.remark
- }})</span>
- <el-button
- class="edit_field"
- type="text"
- style="float: right;border: none;margin-top: 2px;"
- @click="openParamsConfig"
- >
- 配置
- </el-button>
- </div>
- </div>
- </div>
- <div class="structure">
- <div class="title-style bs-title-style">
- 输出字段
- <el-button
- type="text"
- style="float: right;border: none;margin-top: -4px;"
- @click="fieldsetVisible = true"
- >
- 配置
- </el-button>
- </div>
- <div class="field-wrap bs-field-wrap bs-scrollbar">
- <div
- v-for="field in structurePreviewList"
- :key="field.fieldName"
- class="field-item"
- @click="fieldsetVisible = true"
- >
- <span>{{ field.fieldName }}</span> <span
- v-show="field.fieldDesc"
- style="color: #909399;"
- >({{
- field.fieldDesc }})</span>
- <el-button
- class="edit_field"
- type="text"
- style="float: right;border: none;margin-top: 2px;"
- @click="fieldsetVisible = true"
- >
- 配置
- </el-button>
- </div>
- </div>
- </div>
- </div>
- </el-col>
- </el-row>
- <div
- v-if="isEdit"
- class="dataPreView"
- style="margin-top: 12px;"
- >
- <div class="result-view">
- 数据预览
- </div>
- <div class="bs-table-box is-Edit">
- <el-table
- align="center"
- :data="dataPreviewList"
- max-height="400"
- class="bs-el-table bs-scrollbar"
- :border="true"
- >
- <el-table-column
- v-for="(value, key) in dataPreviewList[0]"
- :key="key"
- :label="key"
- align="center"
- show-overflow-tooltip
- :render-header="renderHeader"
- >
- <template slot-scope="scope">
- <span>{{ scope.row[key] }}</span>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <div class="bs-pagination">
- <el-pagination
- class="bs-el-pagination"
- popper-class="bs-el-pagination"
- :current-page="current"
- :page-sizes="[10, 20, 50, 100]"
- :page-size="size"
- :total="totalCount"
- background
- prev-text="上一页"
- next-text="下一页"
- layout="total, prev, pager, next,sizes"
- @size-change="sizeChangeHandle"
- @current-change="currentChangeHandle"
- />
- </div>
- </div>
- <div
- v-if="!isEdit"
- class="dataPreView"
- >
- <el-tabs v-model="activeName">
- <el-tab-pane
- v-loading="tableLoading"
- label="数据预览"
- name="data"
- >
- <div class="bs-table-box">
- <el-table
- align="center"
- :data="dataPreviewList"
- max-height="400"
- :border="true"
- >
- <el-table-column
- v-for="(value, key) in dataPreviewList[0]"
- :key="key"
- :label="key"
- align="center"
- show-overflow-tooltip
- :render-header="renderHeader"
- >
- <template slot-scope="scope">
- <span>{{ scope.row[key] }}</span>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <div class="bs-pagination">
- <el-pagination
- class="bs-el-pagination"
- popper-class="bs-el-pagination"
- :current-page="current"
- :page-sizes="[10, 20, 50, 100]"
- :page-size="size"
- :total="totalCount"
- background
- prev-text="上一页"
- next-text="下一页"
- layout="total, prev, pager, next,sizes"
- @size-change="sizeChangeHandle"
- @current-change="currentChangeHandle"
- />
- </div>
- </el-tab-pane>
- <el-tab-pane
- v-loading="tableLoading"
- label="数据集结构"
- name="structure"
- >
- <div class="bs-table-box">
- <el-table
- max-height="400"
- :data="structurePreviewList"
- :border="true"
- align="center"
- >
- <el-table-column
- align="center"
- show-overflow-tooltip
- prop="fieldName"
- label="字段值"
- />
- <el-table-column
- align="center"
- show-overflow-tooltip
- prop="fieldType"
- label="字段类型"
- />
- <el-table-column
- align="center"
- prop="fieldDesc"
- label="字段描述"
- >
- <template slot-scope="scope">
- <el-input
- v-if="isEdit"
- v-model="scope.row.fieldDesc"
- size="small"
- class="labeldsc bs-el-input"
- />
- <span v-else>{{ scope.row.fieldDesc }}</span>
- </template>
- </el-table-column>
- <el-table-column
- align="center"
- prop="orderNum"
- label="字段排序"
- sortable
- >
- <template slot-scope="scope">
- <el-input
- v-if="isEdit"
- v-model="scope.row.orderNum"
- size="small"
- class="labeldsc bs-el-input"
- />
- <span v-else>{{ scope.row.orderNum }}</span>
- </template>
- </el-table-column>
- <el-table-column
- align="center"
- prop="sourceTable"
- label="字段来源"
- >
- <template slot-scope="scope">
- <el-select
- v-if="isEdit"
- v-model="scope.row.sourceTable"
- popper-class="bs-el-select"
- class="bs-el-select"
- clearable
- filterable
- >
- <el-option
- v-for="table in tableNameList"
- :key="table"
- :label="table"
- :value="table"
- />
- </el-select>
- <span v-else>{{ scope.row.sourceTable }}</span>
- </template>
- </el-table-column>
- </el-table>
- </div>
- </el-tab-pane>
- </el-tabs>
- </div>
- <!-- 字段填充方式 -->
- <el-dialog
- title="提示"
- :visible.sync="fieldDescVisible"
- width="420px"
- append-to-body
- :close-on-click-modal="false"
- custom-class="fieldDescCheck"
- class="bs-dialog-wrap bs-el-dialog"
- >
- <p style="color:var(--bs-el-text);line-height: 24px;padding-left: 10px;display: flex;">
- <i
- class="el-icon-warning"
- style="color: #E6A23C;font-size: 24px;margin-right: 5px;"
- />
- 存在字段描述信息为空,请确认
- </p>
- <span
- slot="footer"
- class="dialog-footer"
- >
- <el-button
- class="bs-el-button-default"
- @click="fieldDescFill"
- >使用字段名填充</el-button>
- <el-button
- class="bs-el-button-default"
- @click="fieldDescEdit"
- >进入编辑</el-button>
- <el-button
- type="primary"
- @click="toSave"
- >继续保存</el-button>
- </span>
- </el-dialog>
- <!-- 字段填充 -->
- <el-dialog
- title="输出字段配置"
- :visible.sync="fieldsetVisible"
- width="1000px"
- append-to-body
- :close-on-click-modal="false"
- :before-close="cancelField"
- class="bs-dialog-wrap bs-el-dialog"
- >
- <div class="bs-table-box">
- <el-table
- class="bs-el-table"
- :data="structurePreviewListCopy"
- :border="true"
- align="center"
- >
- <el-empty slot="empty" />
- <el-table-column
- align="left"
- show-overflow-tooltip
- prop="fieldName"
- label="字段值"
- />
- <el-table-column
- align="center"
- show-overflow-tooltip
- prop="fieldType"
- label="字段类型"
- />
- <el-table-column
- align="center"
- prop="fieldDesc"
- label="字段描述"
- >
- <template slot-scope="scope">
- <el-input
- v-if="isEdit"
- v-model="scope.row.fieldDesc"
- size="small"
- class="labeldsc bs-el-input"
- />
- <span v-else>{{ scope.row.fieldDesc }}</span>
- </template>
- </el-table-column>
- <el-table-column
- align="center"
- prop="orderNum"
- label="字段排序"
- sortable
- >
- <template slot-scope="scope">
- <el-input
- v-if="isEdit"
- v-model="scope.row.orderNum"
- size="small"
- class="labeldsc bs-el-input"
- />
- <span v-else>{{ scope.row.orderNum }}</span>
- </template>
- </el-table-column>
- <el-table-column
- align="center"
- prop="sourceTable"
- label="字段来源"
- >
- <template slot-scope="scope">
- <el-select
- v-if="isEdit"
- v-model="scope.row.sourceTable"
- popper-class="bs-el-select"
- class="bs-el-select"
- clearable
- filterable
- >
- <el-option
- v-for="table in tableNameList"
- :key="table"
- :label="table"
- :value="table"
- />
- </el-select>
- <span v-else>{{ scope.row.sourceTable }}</span>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <span
- slot="footer"
- class="dialog-footer"
- >
- <el-button
- class="bs-el-button-default"
- @click="cancelField"
- >
- 取消
- </el-button>
- <el-button
- type="primary"
- @click="setField"
- >
- 确定
- </el-button>
- </span>
- </el-dialog>
- <!-- 参数配置 -->
- <el-dialog
- title="SQL参数配置"
- :visible.sync="paramsVisible"
- width="1000px"
- append-to-body
- :close-on-click-modal="false"
- :before-close="cancelParam"
- class="bs-dialog-wrap bs-el-dialog"
- >
- <div class="bs-table-box">
- <el-table
- ref="singleTable"
- class="bs-el-table"
- :data="paramsListCopy"
- :border="true"
- align="center"
- >
- <el-empty slot="empty" />
- <el-table-column
- prop="name"
- label="参数名称"
- align="center"
- />
- <el-table-column
- prop="type"
- label="参数类型"
- align="center"
- width="200"
- filterable
- >
- <template slot-scope="scope">
- <el-select
- v-model="scope.row.type"
- popper-class="bs-el-select"
- class="bs-el-select"
- placeholder="请选择"
- >
- <el-option
- v-for="item in typeSelect"
- :key="item.value"
- :label="item.value"
- :value="item.value"
- />
- </el-select>
- </template>
- </el-table-column>
- <el-table-column
- prop="require"
- label="是否必填"
- align="center"
- width="200"
- filterable
- >
- <template slot-scope="scope">
- <el-radio-group v-model="scope.row.require">
- <el-radio :label="1">
- 是
- </el-radio>
- <el-radio :label="0">
- 否
- </el-radio>
- </el-radio-group>
- </template>
- </el-table-column>
- <el-table-column
- prop="value"
- label="参数值"
- align="center"
- >
- <template slot-scope="scope">
- <el-date-picker
- v-if="scope.row.type === 'Date'"
- v-model="scope.row.value"
- type="datetime"
- value-format="yyyy-MM-dd HH:mm:ss"
- placeholder="选择日期时间"
- />
- <el-input
- v-else
- v-model="scope.row.value"
- class="bs-el-input"
- clearable
- placeholder="请输入值"
- />
- </template>
- </el-table-column>
- <el-table-column
- prop="remark"
- label="备注"
- align="center"
- >
- <template slot-scope="scope">
- <el-input
- v-model="scope.row.remark"
- clearable
- class="bs-el-input"
- placeholder="请输入备注"
- />
- </template>
- </el-table-column>
- <el-table-column
- label="操作"
- width="105"
- align="center"
- >
- <template slot="header">
- <el-button
- icon="el-icon-plus"
- type="text"
- class="no-border"
- @click="addParam"
- >
- 添加
- </el-button>
- </template>
- <template slot-scope="scope">
- <el-button
- type="text"
- style="color: #e47470;"
- class="no-border"
- @click="delRow(scope.$index)"
- >
- 删除
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <span
- slot="footer"
- class="dialog-footer"
- >
- <el-button
- class="bs-el-button-default"
- @click="cancelParam"
- >取消</el-button>
- <el-button
- type="primary"
- @click="setParam"
- >确定</el-button>
- </span>
- </el-dialog>
- </el-scrollbar>
- </div>
- </template>
- <script>
- import {
- nameCheckRepeat,
- datasetAdd,
- datasetUpdate,
- datasetExecuteTest,
- getCategoryTree,
- getDataset
- } from 'packages/js/utils/datasetConfigService'
- import { datasourceList } from 'packages/js/utils/dataSourceService'
- import { codemirror } from 'vue-codemirror'
- import 'codemirror/mode/sql/sql.js'
- import 'codemirror/theme/nord.css'
- import 'codemirror/lib/codemirror.css'
- import _ from 'lodash'
- export default {
- name: 'CustomEditForm',
- components: {
- codemirror
- },
- props: {
- isEdit: {
- type: Boolean,
- default: false
- },
- datasetId: {
- type: String,
- default: null
- },
- datasetName: {
- type: String,
- default: ''
- },
- typeId: {
- type: String,
- default: ''
- },
- appCode: {
- type: String,
- default: ''
- }
- },
- data () {
- const validateName = (rule, value, callback) => {
- nameCheckRepeat({
- id: this.datasetId,
- name: value,
- moduleCode: this.appCode
- }).then((r) => {
- if (r) {
- callback(new Error('数据集名称已存在'))
- } else {
- callback()
- }
- })
- }
- return {
- dataForm: {
- id: '',
- name: '',
- typeId: '',
- datasetType: 'custom',
- remark: '',
- // 以下为config配置
- sourceId: '',
- sqlProcess: 'select ',
- paramsList: [],
- fieldDesc: {},
- fieldList: [],
- script: '',
- cacheCoherence: null
- },
- rules: {
- name: [
- { required: true, message: '请输入数据集名称', trigger: 'blur' },
- { validator: validateName, trigger: 'blur' }
- ],
- sourceId: [
- { required: true, message: '请选择数据源', trigger: 'blur' }
- ]
- },
- cOptions: {
- mode: 'text/x-mysql',
- lineNumbers: true,
- lineWrapping: true,
- theme: 'nord',
- extraKey: { Ctrl: 'autocomplete' },
- hintOptions: {
- completeSingle: true
- }
- },
- sourceList: [],
- activeName: 'data',
- dataPreviewList: [],
- structurePreviewList: [],
- structurePreviewListCopy: [],
- msg: '',
- exception: '',
- typeSelect: [
- { value: 'String' },
- { value: 'Integer' },
- { value: 'Double' },
- { value: 'Long' },
- { value: 'Date' }
- ],
- typeName: '',
- categoryData: [],
- passTest: false, // 通过测试
- current: 1,
- size: 10,
- totalCount: 0,
- fieldDescVisible: false,
- fieldsetVisible: false,
- paramsVisible: false,
- tableLoading: false,
- saveLoading: false,
- saveText: '',
- tableNameList: [],
- paramsListCopy: [],
- isTest: false // 是否执行测试
- }
- },
- computed: {
- checkPass () {
- return {
- sqlProcess: this.dataForm.sqlProcess,
- script: this.dataForm.script,
- paramsList: this.dataForm.paramsList
- }
- }
- },
- watch: {
- // 一旦sql、脚本、参数发生变化,将通过测试置为false
- checkPass: {
- handler (value) {
- this.passTest = false
- },
- deep: true
- }
- },
- mounted () {
- this.init()
- },
- methods: {
- /**
- * 初始化
- * 1.获取分类树
- * 2.获取数据源列表
- * 3.如果是编辑,获取数据集详情
- */
- async init () {
- // 获取分类树
- this.categoryData = await getCategoryTree({ type: 'dataset', moduleCode: this.appCode })
- // 如果传入了分类id,需要设置分类id和名称
- if (this.typeId) {
- this.dataForm.typeId = this.typeId
- this.$nextTick(() => {
- try {
- this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
- } catch (error) {
- console.error(error)
- }
- })
- }
- // 获取数据源列表
- this.getDataSource()
- if (!this.datasetId) {
- return
- }
- // 获取详情
- getDataset(this.datasetId).then(res => {
- this.dataForm.id = res.id
- this.dataForm.name = res.name
- this.dataForm.typeId = res.typeId
- this.dataForm.remark = res.remark
- this.dataForm.datasetType = res.datasetType
- this.dataForm.moduleCode = res.moduleCode
- this.dataForm.editable = res.editable
- this.dataForm.sourceId = res.sourceId
- // config 配置
- this.dataForm.sqlProcess = res.config.sqlProcess
- this.dataForm.paramsList = res.config.paramsList ? res.config.paramsList : []
- this.dataForm.fieldDesc = res.config.fieldDesc
- this.dataForm.fieldList = res.config.fieldList
- this.dataForm.cacheCoherence = res.config.cacheCoherence
- // 使用传入的数据集名称 ?
- this.dataForm.name = this.datasetName
- this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
- if (this.dataForm.typeId) {
- this.$nextTick(() => {
- try {
- this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
- } catch (error) {
- console.error(error)
- }
- })
- }
- this.datasetTest(false)
- })
- },
- /**
- * 获取数据源列表
- */
- getDataSource () {
- const params = {
- sourceName: '',
- sourceType: '',
- moduleCode: this.appCode
- }
- datasourceList(params).then(data => {
- this.sourceList = data
- })
- },
- /**
- * 打开参数配置弹窗
- */
- openParamsConfig () {
- this.isTest = false
- this.paramsVisible = true
- },
- /**
- * 删除参数配置
- * @param {*} index
- */
- delRow (index) {
- this.paramsListCopy.splice(index, 1)
- },
- /**
- * 新增参数配置
- */
- addParam () {
- this.paramsListCopy.push({
- name: '',
- type: '',
- value: '',
- status: 1,
- require: 0,
- remark: ''
- })
- },
- /**
- * 取消编辑参数
- */
- cancelParam () {
- this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
- this.paramsVisible = false
- },
- /**
- * 保存参数设置
- */
- setParam () {
- this.dataForm.paramsList = _.cloneDeep(this.paramsListCopy)
- if (this.isTest) {
- this.datasetTest()
- }
- this.paramsVisible = false
- },
- /**
- * 使用字段名填充字段描述
- */
- fieldDescFill () {
- this.structurePreviewList.forEach(field => {
- if (field.fieldDesc === '' || !field.hasOwnProperty('fieldDesc')) {
- field.fieldDesc = field.fieldName
- }
- })
- this.save('form')
- this.fieldDescVisible = false
- },
- /**
- * 打开字段描述编辑弹窗
- */
- fieldDescEdit () {
- this.fieldDescVisible = false
- this.fieldsetVisible = true
- },
- /**
- * 跳过字段描述编辑直接保存
- */
- toSave () {
- this.save('form', true)
- this.fieldDescVisible = false
- },
- /**
- * 取消编辑字段
- */
- cancelField () {
- this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
- this.fieldsetVisible = false
- },
- /**
- * 保存字段设置
- */
- setField () {
- this.structurePreviewList = _.cloneDeep(this.structurePreviewListCopy)
- this.fieldsetVisible = false
- },
- /**
- * 保存
- * @param formName 表单名称
- * @param noCheckToSave 是否不检查直接保存
- */
- save (formName, noCheckToSave = false) {
- if (this.passTest === false) {
- this.$message.error('请确保数据集SQL加工脚本不为空且测试通过')
- return
- }
- if (!this.structurePreviewList.length) {
- this.$message.warning('该自助数据集未生成输出字段,请重新检查')
- return
- }
- if (!noCheckToSave) {
- const temp = this.structurePreviewList.some(item => {
- return item.fieldDesc === '' || !item.hasOwnProperty('fieldDesc')
- }) // true-存在为空
- if (temp) {
- this.fieldDescVisible = true
- return
- }
- }
- const chineseRegex = /[\u4e00-\u9fa5]/
- let hasChinese = false // 判断有无中文
- let ChineseCode = ''
- for (let i = 0; i < this.structurePreviewList.length; i++) {
- if (chineseRegex.test(this.structurePreviewList[i].fieldName)) {
- hasChinese = true
- ChineseCode = this.structurePreviewList[i].fieldName
- break
- }
- }
- if (hasChinese) {
- this.$confirm(`[${ChineseCode}]字段中包含汉字, 是否保继续保存?`, '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- customClass: 'bs-el-message-box'
- }).then(() => {
- this.saveFun(formName)
- }).catch(() => {
- })
- } else {
- this.saveFun(formName)
- }
- },
- /**
- * 保存数据集
- * @param formName
- */
- saveFun (formName) {
- this.$refs[formName].validate((valid) => {
- if (!valid) {
- return false
- }
- // 校验参数名称是否重复
- if (this.dataForm.paramsList.length > 0) {
- const names = this.dataForm.paramsList.map(value => value.name)
- const namesSet = new Set(names)
- if (namesSet.size !== names.length) {
- this.$message.error('参数名称不能重复,请重新输入')
- return
- }
- }
- // 设置字段描述
- const columnMap = {}
- if (this.structurePreviewList.length > 0) {
- this.structurePreviewList.forEach(r => {
- columnMap[r.fieldName] = r.fieldDesc
- })
- this.dataForm.fieldDesc = columnMap
- }
- this.dataForm.fieldList = this.structurePreviewList
- this.saveLoading = true
- this.saveText = '正在保存...'
- const datasetSave = this.dataForm.id === '' ? datasetAdd : datasetUpdate
- const datasetParams = {
- id: this.dataForm.id,
- name: this.dataForm.name,
- typeId: this.dataForm.typeId,
- datasetType: 'custom',
- remark: this.dataForm.remark,
- sourceId: this.dataForm.sourceId,
- moduleCode: this.appCode,
- editable: this.appCode ? 1 : 0,
- config: {
- className: 'com.gccloud.dataset.entity.config.CustomDataSetConfig',
- sourceId: this.dataForm.sourceId,
- sqlProcess: this.dataForm.sqlProcess,
- paramsList: this.dataForm.paramsList,
- fieldList: this.dataForm.fieldList,
- fieldDesc: this.dataForm.fieldDesc
- }
- }
- datasetSave(datasetParams).then(res => {
- this.$message.success('保存成功')
- this.$parent.init(false)
- this.$parent.setType = null
- this.saveLoading = false
- this.saveText = ''
- }).catch(() => {
- this.saveLoading = false
- this.saveText = ''
- })
- this.saveLoading = false
- this.saveText = ''
- })
- },
- /**
- * 解析并运行数据集
- */
- buildParamsAndRun () {
- this.isTest = true
- const reg = /\${(.*?)}/g
- const paramNames = [...new Set([...this.dataForm.sqlProcess.matchAll(reg)].map(item => item[1]))]
- const names = this.dataForm.paramsList.map(item => item.name)
- const params = []
- paramNames.forEach(name => {
- if (names.includes(name)) {
- const param = this.dataForm.paramsList.find(item => item.name === name)
- params.push(param)
- } else {
- params.push({
- name: name,
- type: 'String',
- value: '',
- status: 1,
- require: 0,
- remark: ''
- })
- }
- })
- this.dataForm.paramsList = _.cloneDeep(params)
- this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
- if (this.dataForm.paramsList.length) {
- this.paramsVisible = true
- } else {
- this.datasetTest()
- }
- },
- /**
- * 数据集测试
- * @param val
- */
- datasetTest (val = true) {
- if (this.dataForm.sourceId === '') {
- this.$message.error('请选择数据源')
- return
- }
- if (this.dataForm.sqlProcess === '') {
- this.$message.error('请输入数据集SQL加工脚本')
- return
- }
- if (this.dataForm.paramsList.length > 0) {
- const names = this.dataForm.paramsList.map(value => value.name)
- const namesSet = new Set(names)
- if (namesSet.size !== names.length) {
- this.$message.error('参数名称不能重复,请重新输入')
- return
- }
- }
- // 点击测试初始化分页当前页为1
- if (val === true) {
- this.current = 1
- }
- this.saveLoading = true
- const executeParams = {
- dataSourceId: this.dataForm.sourceId,
- script: this.dataForm.sqlProcess,
- params: this.dataForm.paramsList,
- dataSetType: 'custom',
- size: this.size,
- current: this.current
- }
- datasetExecuteTest(executeParams).then(res => {
- this.dataPreviewList = res.data.list
- this.structurePreviewList = res.structure
- // 输出字段描述合并
- this.structurePreviewList.forEach(field => {
- const fieldInfo = this.dataForm.fieldList.find(item => item.fieldName === field.fieldName)
- if (fieldInfo) {
- field.fieldDesc = fieldInfo.fieldDesc
- field.orderNum = fieldInfo.orderNum
- field.sourceTable = fieldInfo.sourceTable
- }
- })
- this.structurePreviewList.forEach(item => {
- if (!item.hasOwnProperty('orderNum')) {
- this.$set(item, 'orderNum', 0)
- }
- if (!item.hasOwnProperty('sourceTable')) {
- this.$set(item, 'sourceTable', '')
- }
- if (!item.hasOwnProperty('fieldDesc')) {
- this.$set(item, 'fieldDesc', '')
- }
- })
- this.totalCount = res.data.totalCount
- this.tableNameList = res.tableNameList
- // 如果只有一个表,自动填充字段表名
- if (this.tableNameList && this.tableNameList.length === 1) {
- this.structurePreviewList.forEach(item => {
- item.sourceTable = this.tableNameList[0]
- })
- }
- this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
- let paramsNameCheck = false
- this.dataForm.paramsList.forEach(param => {
- const checkList = this.structurePreviewList.filter(item => item.fieldName === param.name)
- if (checkList.length) {
- paramsNameCheck = true
- param.name = ''
- }
- })
- if (paramsNameCheck) {
- this.$message.warning('参数名称不可以与字段名相同!')
- this.passTest = false
- } else {
- if (val) this.$message.success('测试成功')
- this.exception = ''
- this.msg = ''
- this.passTest = true
- }
- this.saveLoading = false
- }).catch((e) => {
- console.log('测试失败', e)
- this.passTest = false
- this.saveLoading = false
- })
- },
- /**
- * 清空分类选择
- */
- clearType () {
- this.typeName = ''
- this.dataForm.typeId = ''
- },
- /**
- * 分类展开高亮
- * @param $event
- */
- setCurrentNode ($event) {
- if ($event) {
- const key = this.dataForm.typeId || null
- this.$refs.categorySelectTree.setCurrentKey(key)
- }
- },
- /**
- * 分类选择
- * @param value
- */
- selectParentCategory (value) {
- this.dataForm.typeId = value.id
- this.typeName = value.name
- this.$refs.selectParentName.blur()
- },
- goBack () {
- this.$emit('back')
- },
- // 每页大小改变触发
- sizeChangeHandle (value) {
- this.size = value
- this.current = 1
- this.datasetTest(false)
- },
- // 当前页数改变
- currentChangeHandle (value) {
- this.current = value
- this.datasetTest(false)
- },
- // 表头添加提示
- renderHeader (h, { column, index }) {
- const labelLong = column.label.length // 表头label长度
- const size = 14 // 根据需要定义标尺,直接使用字体大小确定就行,也可以根据需要定义
- column.minWidth = labelLong * size < 120 ? 120 : labelLong * size // 根据label长度计算该表头最终宽度
- return h('span', { class: 'cell-content', style: { width: '100%' } }, [column.label])
- },
- openNewWindow (url) {
- window.open(url, '_blank')
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import '~packages/assets/style/bsTheme.scss';
- .data-set-scrollbar {
- height: 100%;
- overflow-y: auto;
- overflow-x: none;
- }
- // .tree-box {
- // padding: 0;
- // max-height: 270px;
- // }
- /deep/ .el-input__inner {
- width: 100% !important;
- }
- .page-header {
- display: flex;
- position: relative;
- .page-header-right {
- position: absolute;
- right: 16px;
- }
- }
- .sql-config {
- padding: 0 16px;
- }
- .operation {
- /deep/ .el-select {
- width: 200px !important;
- margin-right: 16px;
- }
- display: flex;
- }
- /deep/ .CodeMirror {
- height: 180px !important;
- font-family: Helvetica, Tahoma;
- // .CodeMirror-scroll {
- // background: #fff;
- // .CodeMirror-gutters {
- // background-color: #f6f7fb;
- // }
- // }
- }
- .no-border {
- border: 0;
- }
- /deep/ .fieldDescCheck {
- .el-dialog__body {
- height: fit-content !important;
- min-height: unset !important;
- }
- }
- .title-style {
- padding: 8px 12px;
- background-color: #f6f7fb;
- border-left: 5px solid var(--bs-el-color-primary);
- margin: 16px 16px 0 0;
- }
- .field-wrap {
- overflow: auto;
- margin-right: 16px;
- .field-item {
- line-height: 32px;
- padding: 0 12px 0 16px;
- cursor: pointer;
- .edit_field {
- display: none;
- }
- &:hover {
- background-color: #f2f7fe;
- .edit_field {
- display: block;
- }
- }
- }
- }
- .right-setting {
- height: 454px;
- overflow: hidden;
- display: flex;
- flex-direction: column;
- .paramConfig {
- max-height: 227px;
- .field-wrap {
- max-height: 175px;
- }
- }
- .structure {
- flex: 1;
- overflow: hidden;
- .field-wrap {
- height: calc(100% - 40px);
- }
- }
- }
- .result-view {
- font-size: 14px;
- font-weight: 600;
- color: var(--bs-el-text);
- position: relative;
- padding: 16px 0;
- padding-left: 12px;
- border-bottom: 1px solid var(--bs-background-1);
- &::before {
- content: "";
- height: 14px;
- position: absolute;
- left: 0;
- top: 50%;
- transform: translateY(-50%);
- border-left: 4px solid var(--bs-el-color-primary);
- }
- }
- .bs-table-box {
- height: 100% !important;
- margin-bottom: 0 !important;
- }
- /deep/ .bs-table-box.is-Edit .el-table {
- max-height: unset !important;
- .el-table__body-wrapper {
- max-height: unset !important;
- }
- }
- .bs-pagination {
- ::v-deep .el-input__inner {
- width: 110px !important;
- border: none;
- background: var(--bs-el-background-1);
- }
- }
- </style>
|