Commit 02c2cc97 authored by 何虹's avatar 何虹 💬

本次提交的说明

parent f7ac309c
......@@ -17,6 +17,7 @@
"build-bundle": "vue-cli-service build --target lib --name hs-sky-ui ./src/packages/index.js"
},
"dependencies": {
"hs-util-js":"^1.0.2",
"axios": "^0.19.2",
"babel-preset-es2015": "^6.24.1",
"core-js": "^3.6.4",
......
<template>
<div
:id='elId'
class="common"
>
<slot></slot>
<hs-jsoneditor
v-model='jsoneditorVisible'
:elInfo='elInfo'
v-bind="$attrs"
v-on="$listeners"
></hs-jsoneditor>
<!-- <jsoneditor
v-model='jsoneditorVisible'
:elInfo='elInfo'
v-bind="$attrs"
v-on="$listeners"
>
</jsoneditor> -->
</div>
</template>
<script>
import commonboxUc from './commonboxUc.js'
export default {
mixins: [commonboxUc],
props: {
elInfo: {}
},
name: 'common-component'
}
</script>
<style scoped>
.common {
width: 100%;
height: 100%;
}
</style>
\ No newline at end of file
import uuidv1 from 'uuid/v1'
export default {
data() {
return {
elId: '',
outBoxDom: null,
jsoneditorVisible: false
}
},
created() {
this.initElid()
},
mounted() {
this.initElid()
setTimeout(() => {
this.showEditJsonDialog()
}, 2000)
},
destroyed() {
if (this.outBoxDom) {
this.outBoxDom.removeEventListener('mousedown', this.boxEventMouse)
this.outBoxDom = null
}
this.chart = null
},
beforeDestroy() {
clearInterval(this.timer)// 清除定时器
this.timer = null
if (this.chart) {
this.chart.clear()
this.chart.dispose()
this.chart = null
}
},
methods: {
initElid() {
if (!this.elId) {
this.elId = uuidv1() // 获取随机id
}
},
boxEventMouse(event) {
const that = this
event.stopPropagation()
if (event.shiftKey && event.altKey && !event.ctrlKey) {
that.jsoneditorVisible = true
}
},
// 弹出可编辑的弹框
showEditJsonDialog() {
this.outBoxDom = document.getElementById(this.elId)
this.outBoxDom && this.outBoxDom.addEventListener('mousedown', this.boxEventMouse)
}
}
}
<template>
<el-dialog
id="jsonEditorBox"
@opened="dialogOpen"
:title='pageTitle'
:visible.sync="dialogVisible"
@closed="dialogClose"
width="95%"
:append-to-body='true'
:close-on-click-modal='false'
>
<div id="jsonEditBox">
<div style="display:flex;">
<div class="editItemBox1">
<div class="editeTitleItem">配置</div>
<div
:id='ideditor1'
style="width: 100%; height: 100%;"
></div>
</div>
<div class="editItemBox2">
<div class="editeTitleItem">模拟数据</div>
<div
:id='ideditor2'
style="width: 100%; height: 100%;"
></div>
</div>
<div
class="editItemBox3"
id="sqlBox"
>
<div class="editeTitleItem">SQL</div>
<el-input
style="width: 100%; height: 100%;border:1px solid #1160f1"
type="textarea"
placeholder="请输入内容"
v-model="textareaSql"
>
</el-input>
</div>
</div>
<el-row :gutter="20">
<div class="buttonBox">
<div class="infopageItem">
<div class="pageItem">
<span>组件名称:{{elInfo.el}}</span>
</div>
<div class="pageItem">
<span>版本号:{{this.controlInfo.version}}</span>
</div>
<div class="pageItem">
<span>时间:{{this.controlInfo.update_time}}</span>
</div>
</div>
<div class="button_hanlde">
<el-switch
v-model="controlInfo.isMock"
active-text="模拟"
inactive-text="正式"
></el-switch>
<el-button
v-if="elInfo.el==='hsTabsDyncForm'"
size='mini'
plain
type="success"
@click='editHsTabsFormColums'
>修改标签内容</el-button>
<el-button
v-if="elInfo.el==='hsDyncFormComponent'"
size='mini'
plain
type="success"
@click='editAnyncColums'
>修改表单</el-button>
<el-button
v-if="elInfo.el&&elInfo.el.includes('hsTable')"
size='mini'
plain
type="success"
@click='editTableColums'
>修改表头</el-button>
<el-button
v-if='false'
v-show="layout"
size='mini'
plain
type="danger"
@click='changControl(1)'
>上一个</el-button>
<el-button
v-if='false'
v-show="layout"
size='mini'
plain
type="warning"
@click='changControl(2)'
>下一个</el-button>
<el-button
v-if='false'
size='mini'
plain
type="success"
@click='execSql'
>模拟数据</el-button>
<el-button
size='mini'
type="danger"
@click="submitToDb"
>提交到数据库</el-button>
<el-button
v-if='false'
size='mini'
type="warning"
@click='resetEdit'
>撤销修改</el-button>
<el-button
v-if='false'
size='mini'
plain
@click='lookPageLogView'
>查看日志</el-button>
<el-button
size='mini'
type="success"
@click='saveAs'
>另存</el-button>
</div>
</div>
</el-row>
</div>
<lookPageLog
@revertVersion='revertVersion_'
:isrequest='isrequest'
@showView='showViewLog'
v-if="lookPageLogVisible"
:elInfo='elInfo'
/>
<tbaleColumsSet
v-model="dialogVisibleTbaleColums"
:tableDataColums='tableDataColums'
:allSourceData='allSourceData'
:mockSourceData='mockSourceData'
:elInfo='elInfo'
:isEditColumns='isEditColumns'
@submit='submitTbaleColumsSet'
:isSubmitSuccessFlage='isSubmitSuccessFlage'
/>
<asyncFormPropSet
v-model="dialogVisibleAsyncFormColumn"
:asyncFormColumns='asyncFormColumns'
@submit='asyncFormPropSubmit'
:elInfo='elInfo'
:controlType='controlType'
/>
<hsTabsFormSet
v-model="dialogVisibleHsTabsForm"
:allSourceData='hsTabsColumsAllSourceData'
@submit='asyncHsTabsSubmit'
:elInfo='elInfo'
>
</hsTabsFormSet>
<el-dialog
title="布局类型选择"
:visible.sync="tipAdminDialogVisible"
width="50%"
:append-to-body='true'
:close-on-click-modal='false'
>
<span class="tipLayoutStyle">请选择保存布局的类型?</span>
<span
slot="footer"
class="dialog-footer"
>
<el-button
size="mini"
type="primary"
@click="submitConfig(0)"
>全局</el-button>
<el-button
size="mini"
type="primary"
@click="submitConfig(1)"
>强制并全局使用</el-button>
<el-button
size="mini"
type="primary"
@click="submitConfig(2)"
>个人</el-button>
<el-button
size="mini"
@click="tipAdminDialogVisible = false"
>取 消</el-button>
</span>
</el-dialog>
</el-dialog>
</template>
<script>
import uuidv1 from 'uuid/v1'
import mockData from './initDbConfigDataJson'
import commonUtility from '../funTools/commonUtility'
import lookPageLog from './lookPageLog.vue'
import asyncFormPropSet from './asyncFormPropSet.vue'
import tbaleColumsSet from './tbaleColumsSet.vue'
import hsTabsFormSet from './hsTabsFormSet'
import 'jsoneditor/dist/jsoneditor.min.css'
import jsoneditor from 'jsoneditor'
// const lookPageLog = r => require.ensure([], () => r(require('./lookPageLog.vue')), 'lookPageLog')
// const asyncFormPropSet = r => require.ensure([], () => r(require('./asyncFormPropSet.vue')), 'asyncFormPropSet')
// const tbaleColumsSet = r => require.ensure([], () => r(require('./tbaleColumsSet.vue')), 'tbaleColumsSet')
export default {
components: { lookPageLog, asyncFormPropSet, tbaleColumsSet, hsTabsFormSet },
name: 'jsoneditor',
props: {
elInfo: {
type: Object,
default() {
return {}
}
},
initStyle: {
type: Object,
default() {
return {}
}
},
value: Boolean,
layout: {},
jsoneditorCloseAfter: {
type: Function,
default() {
return () => {}
}
},
jsoneditorOpenAfter: {
type: Function,
default() {
return () => {}
}
},
allSourceData: {},
controlType: {},
isEditColumns: {}
},
computed: {
pageTitle: function() {
const { appCode, pageName, controlName } = this.controlInfo
return `配置: AppCode: <${appCode}>---pageName: <${pageName}>---controlName: <${controlName}>`
}
},
watch: {
value(val) {
this.dialogVisible = val
},
dialogVisible(val) {
this.$emit('input', val)
}
},
data() {
return {
options: {
mode: 'text',
indentation: 2,
search: false
},
ideditor1: 'b' + uuidv1(),
ideditor2: 'b' + uuidv1(),
editor1: null,
editor2: null,
commonData: {},
copyJsoneditorData: null,
dialogVisible: false,
lookPageLogVisible: false,
isrequest: false,
textareaSql: '',
dialogVisibleTbaleColums: false,
mockSourceData: [],
tableDataColums: [],
dialogVisibleAsyncFormColumn: false,
asyncFormColumns: [],
isSubmitSuccessFlage: '',
errorEdit: 0,
tipAdminDialogVisible: false,
dialogVisibleHsTabsForm: false,
hsTabsColums: [],
hsTabsColumsAllSourceData: {
config: {},
sourceData: []
},
controlInfo: {
appCode: '',
pageName: '',
controlName: '',
version: '',
updateTime: '',
isMock: true,
controlType: ''
}
}
},
methods: {
asyncHsTabsSubmit(data) {
const datas = {
config: data.config
}
this.saveData(datas).then(res => {
this.dialogVisibleHsTabsForm = false
this.editor1.set(data.config)
})
},
editHsTabsFormColums() {
const config = this.editor1.get()
this.hsTabsColumsAllSourceData.config = config
this.dialogVisibleHsTabsForm = true
},
submitConfig(num) {
this.openTips(
'此操作将覆盖数据库中的数据, 是否继续?',
this.submitData,
num
)
},
submitTbaleColumsSet(columnsConfig, flage) {
const config = this.editor1.get()
config.columnsConfig = columnsConfig
this.editor1.set(config)
const sql = this.textareaSql
const data = {
dbName: this.controlInfo.dbName,
appCode: this.controlInfo.appCode,
pageName: this.controlInfo.pageName,
controlName: this.controlInfo.controlName,
config, // this.editor1.get(),
data: this.editor2.get(),
querySql: sql,
mockData: this.controlInfo.isMock ? 1 : 0,
controlType: this.elInfo.el || ''
}
this.$listeners.webChartConfigSave(data).then(() => {
this.$message.success('设置成功')
if (flage === 'columnStyleSet') {
this.isSubmitSuccessFlage = 'columnStyleSet'
} else {
this.isSubmitSuccessFlage = 'tbaleColumsSet'
this.dialogVisibleTbaleColums = false
}
this.editor1.set(config)
})
},
asyncFormPropSubmit(data) {
const config = this.editor1.get()
config.formColumn = data
const datas = {
config: config
}
this.saveData(datas).then(res => {
this.dialogVisibleAsyncFormColumn = false
this.editor1.set(datas.config)
})
},
saveData(datas) {
const data = {
dbName: this.controlInfo.dbName,
appCode: this.controlInfo.appCode,
pageName: this.controlInfo.pageName,
controlName: this.controlInfo.controlName,
config: datas.config || this.editor1.get(),
data: this.editor2.get(),
querySql: this.textareaSql,
mockData: this.controlInfo.isMock ? 1 : 0
}
return this.$listeners.webChartConfigSave(data)
},
editAnyncColums() {
this.dialogVisibleAsyncFormColumn = true
const config = this.editor1.get()
this.asyncFormColumns = config.formColumn
},
editTableColums() {
this.dialogVisibleTbaleColums = true
const config = this.editor1.get()
this.mockSourceData = this.editor2.get()
if (config && config.columnsConfig && config.columnsConfig.length) {
this.tableDataColums = [...config.columnsConfig]
} else {
this.tableDataColums = [{}]
}
this.tableDataColums.forEach((item, index) => {
if (item.childs) {
this.tableDataColums.splice(index, 1, ...item.childs)
}
})
},
// 折线图的模拟数据
getMockData(type) {
return mockData[type]
},
changControl(flage) {
if (this.layout) {
const list = this.layout.filter(item => item.isRequestControl)
const currIndex = list.findIndex(
item => item.control.position === this.elInfo.position
)
let nextIndex = 0
let target = null
if (flage === 1) {
// 上一个
if (currIndex === 0) {
this.$message('已经是第一个了')
return
}
nextIndex = currIndex - 1
target = list[nextIndex]
} else {
// 下一个
if (currIndex === list.length - 1) {
this.$message('已经是最后个了')
return
}
nextIndex = currIndex + 1
target = list[nextIndex]
}
this.elInfo = target.control
this.getPageInfo(target.control)
}
},
lookPageLogView() {
this.lookPageLogVisible = true
this.isrequest = !this.isrequest
},
showViewLog(data) {
this.editor1.set(data.config)
this.editor2.set(data.sourceData)
this.textareaSql = data.sql || ''
this.showView()
},
revertVersion_(parm) {
this.$listeners.webChartConfigRevert.then(res => {
this.getPageInfo()
this.isrequest = !this.isrequest
})
},
execSql() {
const data = {
execSql: this.query_sql,
dbName: this.controlInfo.dbName
}
this.$listeners.execSql(data).then(res => {
this.editor2.set(res)
})
},
getPageInfo(info = this.elInfo) {
const { position, pageName, appCode } = info
const data = {
controlName: position,
appCode: appCode,
pageName: pageName
}
this.$listeners.webChartConfigQuery(data).then(
res => {
const data = res.data
if (data && data.length) {
// 以后端返回的控件信息为准
const {
app_code,
control_name,
json_config,
json_data,
page_name,
query_sql,
is_mock,
version,
update_time
} = data[0]
this.controlInfo.appCode = app_code
this.controlInfo.controlName = control_name
this.controlInfo.pageName = page_name
this.controlInfo.version = version
this.controlInfo.updateTime = update_time
this.controlInfo.isMock = !!is_mock
const jsonData = {
config: JSON.parse(json_config),
sourceData: JSON.parse(json_data),
sql: query_sql || ''
}
this.copyJsoneditorData = JSON.parse(JSON.stringify(jsonData))
this.setJson(jsonData)
this.textareaSql = query_sql || ''
} else {
// 加载本地模拟数据
this.initImportOrLocalMockData()
}
}
)
},
// 把当页的全部存储到本地
saveAs() {
const data = {
dbName: this.controlInfo.dbName,
appCode: this.controlInfo.appCode,
pageName: this.controlInfo.pageName
}
this.$listeners.saveAsDataToLocal(data)
},
dialogClose() {
this.dialogVisible = false
this.jsoneditorCloseAfter()
this.$emit('dialogClose')
},
dialogOpen() {
this.revertVersion = false
// 初始化appCode pageName 等等
const { appCode, pageName } = commonUtility.getUrlParams()
this.controlInfo.appCode = appCode
this.controlInfo.pageName = pageName
this.controlInfo.controlName = this.elInfo.position
if (!this.elInfo.appCode) {
this.elInfo.appCode = appCode
}
if (!this.elInfo.pageName) {
this.elInfo.pageName = pageName
}
this.getPageInfo()
this.jsoneditorOpenAfter()
},
// 加载传入的数据或者本地模拟数据
initImportOrLocalMockData() {
const mockdata = this.getMockData(this.elInfo.el)
if (!mockdata) {
this.$message.error(this.elInfo.el + '----请配置模拟数据!')
this.setJson({ config: {}, sourceData: [] })
return
}
this.copyJsoneditorData = JSON.parse(JSON.stringify(mockdata))
if (this.allSourceData && this.allSourceData.loadExisData) {
// 加载请求回来的数据
this.setJson(this.allSourceData)
} else {
this.setJson(mockdata)
}
this.textareaSql = this.copyJsoneditorData.sql
},
resetEdit() {
this.openTips('是否确定撤销修改?', this.setOldJson)
},
setOldJson() {
this.setJson(this.copyJsoneditorData)
},
submitToDb() {
this.openTips('此操作将覆盖数据库中的数据, 是否继续?', this.submitData)
},
openTips(message, fun, parm) {
this.$confirm(message, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
fun(parm)
})
.catch(e => {
console.log(e)
this.$message.error(
'已取消-请保证json格式的完整性!,最左边没有就配置为{},中间没有就配置为[]'
)
})
},
submitData() {
const editor1Config = this.editor1.get()
const editor2Config = this.editor2.get()
this.errorEdit = 2
console.log(this.elInfo, this.controlInfo)
// 简化数据获取
const appCode = this.controlInfo.appCode
const sql = this.textareaSql
const controlName = this.controlInfo.controlName || this.elInfo.position
if (!controlName) {
this.$message.error('controlName不存在')
console.log(this.elInfo, this.controlInfo)
return
}
const data_ = {
dbName: this.controlInfo.dbName,
appCode: appCode,
pageName: this.controlInfo.pageName,
controlName: controlName,
config: editor1Config,
data: editor2Config,
querySql: sql,
mockData: this.controlInfo.isMock ? 1 : 0
}
this.$listeners.webChartConfigSave(data_).then(() => {
this.$message.success('设置成功')
})
},
setJson(data) {
const { config, sourceData } = JSON.parse(JSON.stringify(data))
if (!this.editor1) {
this.drow(this.ideditor1, config, 'editor1')
this.drow(this.ideditor2, sourceData, 'editor2')
} else {
this.editor1.set(config)
this.editor2.set(sourceData)
}
},
showView() {
this.lookPageLogVisible = false
this.showEchart()
},
showEchart() {
const config = this.editor1.get()
const sourceData = this.editor2.get()
this.commonData = {
config,
sourceData
}
},
drow(el, json = {}, flage) {
const container = document.getElementById(el)
this[flage] = new jsoneditor(container, this.options)
this[flage].set(json)
}
}
}
</script>
<style scoped>
.jsonEditorBox >>> .el-message-box {
background-color: #f6f6f9 !important;
color: #040404 !important;
}
.jsonEditorBox >>> .el-message-box__content {
color: #040404 !important;
}
.jsonEditorBox >>> .el-message-box > .el-button {
color: #040404 !important;
background-color: #4a4d5d4f !important;
}
.buttonBox {
padding-top: 30px;
padding-bottom: 20px;
display: flex;
}
.editItemBox1 {
flex: 1;
height: 400px;
}
.editItemBox2 {
flex: 1;
height: 400px;
}
.editItemBox3 {
flex: 2;
height: 400px;
}
.editeTitleItem {
text-align: center;
font-weight: bold;
font-family: '宋体';
}
.pageItem {
margin-right: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.infopageItem {
display: flex;
}
.button_hanlde {
position: absolute;
right: 10px;
}
#sqlBox >>> .el-textarea__inner {
height: 400px;
}
.tipLayoutStyle {
text-align: center;
}
</style>
import _ from 'lodash'
import tableHandle from './tableHandle'
const emptyList = [undefined, null]
/**
* URL编码;
* @param {参数} param
*/
function toParams(param) {
var result = ''
for (const name in param) {
if (typeof param[name] !== 'function') {
result += '&' + name + '=' + encodeURI(param[name])
}
}
return result.substring(1)
}
function getUrlParams() {
const { db_name, is_mock, db_code } = getURLParameters()
const { appCode, pageName } = parseAppCodePageName()
const isMock = emptyList.includes(is_mock) ? 1 : is_mock
const obj = _.cloneDeep({
dbName: db_name || '',
appCode,
pageName,
isMock,
dbCode: db_code
})
return obj
}
function getSysParams() {
const { db_name, db_code } = getURLParameters()
const {
appCode,
pageName
} = parseAppCodePageName()
const obj = _.cloneDeep({
dbName: db_name,
appCode,
pageName: pageName,
dbCode: db_code,
pageCode: pageName
})
return obj
}
function getURLParameters(url) {
const url_ = url || location.href
const obj = (url_.match(/([^?=&]+)(=([^&]*))/g) || []).reduce(
(a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a),
{}
)
for (const k in obj) {
obj[k] = typeof obj[k] === 'string' ? decodeURIComponent(obj[k]) : obj[k]
}
return obj
}
// 获取登录信息
function parseGlobalParams() {
const globalParam = {}
let user_info = sessionStorage['user_info']
if (user_info && user_info !== 'undefined') {
user_info = JSON.parse(decodeURIComponent(user_info))
}
Object.assign(globalParam, user_info)
return globalParam
}
// 解析queryBi dync页面路由上的appCode 和pageName
function parseAppCodePageName() {
const hash = decodeURIComponent(location.hash)
const hostSplit = hash.split('?')
let target = hostSplit[0]
// 如果说最后一位是‘/’ 则删除掉
if (target.endsWith('/')) {
target = target.substr(0, target.length - 1)
}
const targetSplit = target.split('/')
const length = targetSplit.length
let pageName = targetSplit[length - 1]
const appCode = targetSplit[length - 2]
if (pageName.includes('/')) {
pageName = pageName.split('/')[0]
}
if (pageName.includes('?')) {
pageName = pageName.split('?')[0]
}
return {
appCode,
pageName
}
}
function filterSingleRow(newObj, oldObj, prop = 'id') {
delete newObj.isSelected
delete oldObj.isSelected
const _newObj = _.cloneDeep(newObj)
const _oldObj = _.cloneDeep(oldObj)
const result = {}
for (const p in _newObj) {
if ((_oldObj[p] !== _newObj[p] && !emptyList.includes(_newObj[p])) || p === prop) {
result[p] = _newObj[p]
}
}
return result
}
// newData:当前数据.oldData:原始数据,primaryKey;主键id,reservedObj:保留字段
function comparisonArray(newData_, oldData_, primaryKey, reservedArray = []) {
const newData = _.cloneDeep(newData_)
const oldData = _.cloneDeep(oldData_)
const emptyValue = [undefined, 'undefined', '']
// 1,找出原始数据中所有的id
const old_ids = oldData.reduce((pre, curr) => {
const id = curr[primaryKey]
if (id) {
pre.push(id)
}
return pre
}, [])
// 2,找出新数据中所有项的id
const new_ids = newData.reduce((pre, curr) => {
const id = curr[primaryKey]
if (id) {
pre.push(id)
}
return pre
}, [])
// 3,找出删除项
const delete_ids = old_ids.filter(item => {
if (!new_ids.includes(item)) {
return item
}
})
const newItems = newData_.filter(item => {
if (item.iUpdateStatus === 1) {
return item
}
})
// 找出修改项目
const edit_item = newData.filter(item => {
delete item.isSelected
const id = item[primaryKey]
const curr_old_item = oldData.find(element => {
if (element[primaryKey] === id && item.iUpdateStatus !== 1) {
return element
}
})
if (id && curr_old_item) {
// 找出变化的字段 并且保留必要字段
for (const key in curr_old_item) {
const hasKey = key in item
if (!hasKey) { // 如果这个字段不在现有行中 则视为删除了
item[key] = ''
} else { // 如果字段对应的值相等 则视为 没更改 提交数据时把这个这段排除
if (curr_old_item[key] === item[key] && key !== primaryKey && !reservedArray.includes(key)) {
delete item[key]
}
}
}
const length1 = Object.keys(item).length
if (length1 > 1) {
return item
}
}
})
// 组装数据
// 为新增项加一个标示
newItems.forEach((item, index) => {
delete item.isSelected
// 删除空值
for (const key in item) {
const value = item[key]
if (emptyValue.includes(value)) {
delete item[key]
}
}
delete item._columns
})
// 筛选出非空项
const newItems_ = newItems.filter(item => Object.keys(item).length)
// 为修改项加标示
edit_item.filter(item => Object.keys(item).length).forEach(item => {
delete item.isSelected
for (const k in item) {
if (item[k] === undefined) {
item.k = ''
}
}
if (Object.keys(item).length > 1) {
item.iUpdateStatus = 2
}
})
const delete_items = []
delete_ids.forEach(item => {
const parm = {
iUpdateStatus: 4
}
parm[primaryKey] = item
delete_items.push(parm)
})
const result = [...edit_item, ...delete_items, ...newItems_]
return result
}
function checkRowChange(newData, oldData) {
for (const n_k in newData) {
if (oldData[n_k] !== newData[n_k]) {
return
}
}
return true
}
function checkListChange(newList, oldList, primaryKey) {
if (newList.length !== oldList.length) return false
for (let i = 0; i < newList.length; i++) {
const item = newList[i]
const id = item[primaryKey]
const targetOldItem = oldList.find(x => x[primaryKey] === id)
if (!targetOldItem) return
const r = checkRowChange(item, targetOldItem)
return r
}
return true
}
function comparisonJson(newData_, oldData_, primaryKey, reservedArray = []) {
const newData = _.cloneDeep(newData_)
const oldData = _.cloneDeep(oldData_)
const emptyValue = [undefined, 'undefined']
const iUpdateStatus = newData.iUpdateStatus
if (iUpdateStatus === 1) { // 新增
for (const key in newData) {
if (key === '') {
delete newData[key]
}
const value = newData[key]
if (emptyValue.includes(value)) {
delete newData[key]
}
}
} else { // 修改
for (const key in newData) {
if (key === '') {
delete newData[key]
}
if (newData[key] === oldData[key] && key !== primaryKey && !reservedArray.includes(key)) {
delete newData[key]
}
}
newData.iUpdateStatus = 2
}
delete newData._columns
return newData
}
function getClientHeight() {
var clientHeight = 0
if (document.body.clientHeight && document.documentElement.clientHeight) {
clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
} else {
clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
}
return clientHeight
}
function getClientWidth() {
var clientWidth = 0
if (document.body.clientWidth && document.documentElement.clientWidth) {
clientWidth = (document.body.clientHeight < document.documentElement.clientWidth) ? document.body.clientWidth : document.documentElement.clientWidth
} else {
clientWidth = (document.body.clientWidth > document.documentElement.clientWidth) ? document.body.clientWidth : document.documentElement.clientWidth
}
return clientWidth
}
// 给webframe壳子发消息
function sendErrorToWebframe(err) {
var data = {}
data.type = 'errorMSg'
data.data = err
console.log(data)
top.postMessage(data, '*')
}
function getType(data, type) {
const inner = Object.prototype.toString.call(data) // [object String]
if (inner === type) return true
// Object.prototype.toString.call(1) // [object Number]
// Object.prototype.toString.call(true) // [object Boolean]
// Object.prototype.toString.call(Symbol()) // [object Symbol]
// Object.prototype.toString.call(undefined) // [object Undefined]
// Object.prototype.toString.call(null) // [object Null]
// Object.prototype.toString.call(new Function()) // [object Function]
// Object.prototype.toString.call(new Date()) // [object Date]
// Object.prototype.toString.call([]) // [object Array]
// Object.prototype.toString.call(new RegExp()) // [object RegExp]
// Object.prototype.toString.call(new Error()) // [object Error]
// Object.prototype.toString.call(document) // [object HTMLDocument]
// Object.prototype.toString.call(window) // [object global] window 是全局对象 global 的引用
}
function isObject(data) {
return Object.prototype.toString.call(data) === '[object Object]'
}
function isNull(data) {
return Object.prototype.toString.call(data) === '[object Null]'
}
function isUndefined(data) {
return Object.prototype.toString.call(data) === '[object Undefined]'
}
function isBoolean(data) {
return Object.prototype.toString.call(data) === '[object Boolean]'
}
function isNumber(data) {
return Object.prototype.toString.call(data) === '[object Number]'
}
function isFunction(data) {
return Object.prototype.toString.call(data) === '[object Function]'
}
function isArray(data) {
return Object.prototype.toString.call(data) === '[object Array]'
}
function hasClass(dom, selector) {
if (dom.classList.contains(selector)) {
return true
} else {
return false
}
}
export default {
getUrlParams,
parseGlobalParams,
parseAppCodePageName,
filterSingleRow,
comparisonJson,
comparisonArray,
_,
cloneDeep: _.cloneDeep, // 深拷贝
getURLParameters,
getSysParams,
getClientHeight,
getClientWidth,
sendErrorToWebframe,
checkRowChange,
checkListChange,
toParams,
tableHandle,
getType,
isObject,
isNull,
isBoolean,
isUndefined,
isNumber,
isFunction,
isArray,
hasClass
}
class TableHandle {
constructor() {
this.moduleName = 'TableHandle'
}
/**
*把index1 和 index2交换
* @param {*} arr 数据源
* @param {*} index1
* @param {*} index2
*/
swapArr(arr, index1, index2) {
arr[index1] = arr.splice(index2, 1, arr[index1])[0]
return arr
}
// 向前移动一格
moveUp(arrayData, index1, order = 'order') {
if (index1 >= arrayData.length) return arrayData
let index2 = index1 - 1
if (index2 < 0) {
index2 = arrayData.length - 1
}
const index1Order = arrayData[index1][order]
const index2Order = arrayData[index2][order]
arrayData[index1][order] = index2Order
arrayData[index2][order] = index1Order
// 再交换两个元素的位置
this.swapArr(arrayData, index1, index2)
}
// 向下移动一格
moveDown(arrayData, index1, order = 'order') {
if (index1 >= arrayData.length) return arrayData
let index2 = index1 + 1
if (arrayData.length <= index2) {
index2 = 0
}
const index1Order = arrayData[index1][order]
const index2Order = arrayData[index2][order]
arrayData[index1][order] = index2Order
arrayData[index2][order] = index1Order
// 再交换两个元素的位置
this.swapArr(arrayData, index1, index2)
}
/**
* 向下移动逻辑 有两种复杂情况
* 如果移动行中有最后一项和第一项(0,1,8,9) 这种情况移动顺序是1,0,9,8
* 1,3,5,6 这种移动顺序是 6,5,3,1
* @param {*} array
* @param {*} listIndex
* @param {*} order
*/
batchDown(array, listIndex, order = 'order') {
// 同时包含第一项和最后一项时
const list = []
const itemLast = listIndex[listIndex.length - 1]
const lastIndex = listIndex.length - 1
listIndex.forEach((item, index) => {
if (item - itemLast === index - lastIndex) {
list.push(listIndex[index])
}
})
const max = Math.min(...list)
const maxIndex = listIndex.findIndex(x => x === max)
const spliceList = listIndex.splice(maxIndex, lastIndex)
spliceList.reverse()
let listIndexReverse = listIndex// listIndex.reverse()
if (listIndex.includes(0) && listIndex.includes(array.length - 1)) {
listIndexReverse = listIndex
} else {
listIndexReverse = listIndex.reverse()
}
listIndexReverse.push(...spliceList)
listIndexReverse.forEach(index => {
this.moveDown(array, index, order)
})
}
/**
* 向上移动 也有两种复杂情况
* 如果移动行中有最后一项和第一项(0,1,8,9) 这种情况移动顺序是8,9,0,1
* 1,3,5,6 这种移动顺序是 1,3,5,6
* @param {*} array
* @param {*} listIndex
* @param {*} order
*/
batchUp(array, listIndex, order = 'order') {
// 同时包含第一项和最后一项时
const list = []
const item0 = listIndex[0]
listIndex.forEach((item, index) => {
if (index - item0 === listIndex[index]) {
list.push(listIndex[index])
}
})
const max = Math.max(...list)
const maxIndex = listIndex.findIndex(x => x === max)
const spliceList = listIndex.splice(0, maxIndex + 1)
if (listIndex.includes(0) && listIndex.includes(array.length - 1)) {
const index1 = listIndex.shift()
listIndex.push(index1)
}
listIndex.push(...spliceList)
listIndex.forEach(index => {
this.moveUp(array, index, order)
})
}
batchTop(array, listIndex, order = 'order') {
listIndex.forEach((x, index) => {
let l = x - index
while (l > 0 && x > 0) {
this.moveUp(array, x, order)
x--
l--
}
})
}
batchBottom(array, listIndex, order = 'order') {
listIndex.reverse()
const arrayLength = array.length
listIndex.forEach((x, index) => {
const ducex = arrayLength - x - 1
let l = ducex - index
while (l > 0 && x >= 0) {
this.moveDown(array, x, order)
x++
l--
}
})
}
}
// const list = [{ order: 1, name: 1 }, { order: 2, name: 2 }, { order: 3, name: 3 }, { order: 4, name: 4 }, { order: 5, name: 5 }, { order: 6, name: 6 }, { order: 7, name: 7 }]
// const t = new TableHandle()
// // t.batchTop(list, [0, 3, 5, 6])
// // console.log(list)
// t.batchBottom(list, [1, 2, 3])
// console.log(list)
export default new TableHandle()
......@@ -70,7 +70,7 @@
</div>
</template>
<script>
import commonUtility from '../funTools/commonUtility'
import hsUtil from 'hs-util-js'
import _ from 'lodash'
import Sortable from 'sortablejs'
import commonMixins from '../ucClass/commonMixins'
......@@ -206,7 +206,7 @@ export default {
this.tableDataLeft = this.removeUniq(this.tableDataLeft, isSelectedList)
},
async showDialog() {
const getClientWidth = commonUtility.getClientWidth()
const getClientWidth = hsUtil.System.getClientWidth()
this.tableWith = getClientWidth / 2 + 'px'
// 弹出之前做逻辑判断
const { value } = this.configData
......@@ -458,7 +458,7 @@ export default {
selectIndexData.push(index)
}
})
commonUtility.tableHandle.batchUp(this.tableDataRight, selectIndexData)
hsUtil.TableHandle.batchUp(this.tableDataRight, selectIndexData)
},
/**
* 下移动
......@@ -470,7 +470,7 @@ export default {
selectIndexData.push(index)
}
})
commonUtility.tableHandle.batchDown(this.tableDataRight, selectIndexData)
hsUtil.TableHandle.batchDown(this.tableDataRight, selectIndexData)
}
}
}
......
......@@ -179,7 +179,7 @@
<script>
import { videoPlayer } from 'vue-video-player'
import commonUtility from '../funTools/commonUtility'
import hsUtil from 'hs-util-js'
import 'video.js/dist/video-js.css'
import _ from 'lodash'
import axios from 'axios'
......@@ -383,7 +383,7 @@ export default {
initConfig() {
const { config } = this.allSourceData
const configData = Object.assign(this.configData_, _.cloneDeep(config))
const { appCode } = commonUtility.getSysParams()
const { appCode } = hsUtil.System.getSysParams()
configData.appCode = configData.appCode || appCode
return configData
},
......
......@@ -197,7 +197,7 @@
<script>
import uuidv1 from 'uuid/v1'
import mockData from '../common/initDbConfigDataJson'
import commonUtility from '../funTools/commonUtility'
import hsUtil from 'hs-util-js'
import lookPageLog from '../common/lookPageLog.vue'
import asyncFormPropSet from '../common/asyncFormPropSet.vue'
import tbaleColumsSet from '../common/tbaleColumsSet.vue'
......@@ -333,7 +333,6 @@ export default {
mockData: this.controlInfo.isMock ? 1 : 0,
controlType: this.elInfo.el || ''
}
// rootHttpClient.WebChartConfigModule
this.$listeners.webChartConfigSave(data).then(() => {
this.$message.success('设置成功')
if (flage === 'columnStyleSet') {
......@@ -368,7 +367,6 @@ export default {
mockData: this.controlInfo.isMock ? 1 : 0
}
return this.$listeners.webChartConfigSave(data)
//return rootHttpClient.WebChartConfigModule.webChartConfigSave(data)
},
editAnyncColums() {
this.dialogVisibleAsyncFormColumn = true
......@@ -438,12 +436,6 @@ export default {
this.getPageInfo()
this.isrequest = !this.isrequest
})
// rootHttpClient.WebChartConfigModule.webChartConfigRevert(parm).then(
// res => {
// this.getPageInfo()
// this.isrequest = !this.isrequest
// }
// )
},
execSql() {
const data = {
......@@ -453,9 +445,6 @@ export default {
this.$listeners.execSql(data).then(res => {
this.editor2.set(res)
})
// rootHttpClient.WebChartConfigModule.execSql(data).then(res => {
// this.editor2.set(res)
// })
},
getPageInfo(info = this.elInfo) {
const { position, pageName, appCode } = info
......@@ -464,7 +453,6 @@ export default {
appCode: appCode,
pageName: pageName
}
//rootHttpClient.WebChartConfigModule.webChartConfigQuery(data)
this.$listeners.webChartConfigQuery(data).then(
res => {
const data = res.data
......@@ -510,7 +498,6 @@ export default {
pageName: this.controlInfo.pageName
}
this.$listeners.saveAsDataToLocal(data)
//rootHttpClient.WebChartConfigModule.saveAsDataToLocal(data)
},
dialogClose() {
this.dialogVisible = false
......@@ -520,7 +507,7 @@ export default {
dialogOpen() {
this.revertVersion = false
// 初始化appCode pageName 等等
const { appCode, pageName } = commonUtility.getUrlParams()
const { appCode, pageName } = hsUtil.System.getUrlParams()
this.controlInfo.appCode = appCode
this.controlInfo.pageName = pageName
this.controlInfo.controlName = this.elInfo.position
......@@ -602,9 +589,6 @@ export default {
this.$listeners.webChartConfigSave(data_).then(() => {
this.$message.success('设置成功')
})
// rootHttpClient.WebChartConfigModule.webChartConfigSave(data_).then(() => {
// this.$message.success('设置成功')
// })
},
setJson(data) {
const { config, sourceData } = JSON.parse(JSON.stringify(data))
......
......@@ -2,19 +2,16 @@
<div style='width:100%;height:100%'>
<div :id="elId"
style='width:100%;height:100%;'></div>
<jsoneditor
<hs-jsoneditor
v-model='jsoneditorVisible'
:elInfo='elInfo'
:layout='layout'
:jsoneditorCloseAfter='jsoneditorCloseAfter'
:jsoneditorOpenAfter='jsoneditorOpenAfter'
>
</jsoneditor>
v-bind="$attrs"
v-on="$listeners"
></hs-jsoneditor>
</div>
</template>
<script>
import jsoneditor from '../common/jsoneditor'
import mockData from '../common/initDbConfigDataJson'
import ucComponent from '../ucClass/uc_component'
import echartResize from './echartResize'
......@@ -22,9 +19,6 @@ import _ from 'lodash'
import DataTool from './dataTool'
export default {
mixins: [ucComponent, echartResize],
components: {
jsoneditor
},
name: 'hs-line-bar',
props: {
elInfo: {
......
......@@ -72,7 +72,7 @@
</template>
<script>
import commonMixins from '../ucClass/commonMixins'
import commonUtility from '../funTools/commonUtility'
import hsUtil from 'hs-util-js'
export default {
mixins: [commonMixins],
name: 'lookup-component',
......@@ -460,7 +460,7 @@ export default {
selectIndexData.push(index)
}
})
commonUtility.tableHandle.batchUp(list, selectIndexData)
hsUtil.TableHandle.batchUp(list, selectIndexData)
},
/**
* 下移动
......@@ -473,7 +473,7 @@ export default {
selectIndexData.push(index)
}
})
commonUtility.tableHandle.batchDown(list, selectIndexData)
hsUtil.TableHandle.batchDown(list, selectIndexData)
}
}
}
......
......@@ -16,7 +16,6 @@
<el-button slot="append" icon="el-icon-search" @click='showDialog' ></el-button>
</el-input>
</div>
<el-dialog
@open='openDialog'
:close-on-click-modal='false'
......@@ -121,7 +120,7 @@
</div>
</template>
<script>
import commonUtility from '../funTools/commonUtility'
import hsUtil from 'hs-util-js'
import commonMixins from '../ucClass/commonMixins'
import _ from 'lodash'
export default {
......@@ -366,7 +365,7 @@ export default {
},
async showDialog() {
console.log('showDialog')
const getClientWidth = commonUtility.getClientWidth()
const getClientWidth = hsUtil.System.getClientWidth()
this.tableWithLeft = getClientWidth / 2 + 'px'
this.tableWithRight = getClientWidth / 2 - 66 + 'px'
if (this.value) {
......@@ -582,7 +581,7 @@ export default {
selectIndexData.push(index)
}
})
commonUtility.tableHandle.batchUp(this.rightTabeData, selectIndexData)
hsUtil.TableHandle.batchUp(this.rightTabeData, selectIndexData)
},
/**
* 下移动
......@@ -594,7 +593,7 @@ export default {
selectIndexData.push(index)
}
})
commonUtility.tableHandle.batchDown(this.rightTabeData, selectIndexData)
hsUtil.TableHandle.batchDown(this.rightTabeData, selectIndexData)
}
},
mounted() {}
......
......@@ -338,7 +338,6 @@ import tableDeatil from './tableDetail'
import childItem from './ItemComponentChild'
import tbaleColumsSet from '../common/tbaleColumsSet'
import tableTool from './tableColumsTrans'
import ucComponent from '../ucClass/uc_component'
import rowTable from './rowTable'
import { add } from 'mathjs'
import commonMixins from '../ucClass/commonMixins'
......@@ -717,7 +716,7 @@ export default {
paramsData.json_data = JSON.stringify(sourceData)
paramsData.is_mock = 1
paramsData.query_sql = ''
} else if(Array.isArray(resData)&& resData.length){
} else if (Array.isArray(resData) && resData.length) {
paramsData = resData[0]
}
const { query_sql, json_config, json_data, is_mock } = paramsData
......
import axios from 'axios'
import { Notification, Loading } from 'element-ui'
import hsUtil from 'hs-util-js'
import store from '@/store/storeAll'
import httpClient from './startUp'
let fullLoading
function showLoading() {
fullLoading = Loading.service({
lock: true,
text: '加载中...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0)'
})
setTimeout(_ => {
fullLoading.close()
}, 10000)
}
function closeLoading() {
fullLoading && fullLoading.close()
}
let loading_request_count = 0
function show_full_screen_loading() {
if (loading_request_count === 0) {
showLoading()
}
loading_request_count++
}
function hide_full_screen_loading() {
if (loading_request_count <= 0) return
loading_request_count--
if (loading_request_count === 0) {
closeLoading()
}
}
// 增加一个response拦截器
axios.interceptors.response.use(
function(response) {
hide_full_screen_loading()
if (response.data) {
const { error_detail, error_title } = response.data
if (error_title || error_detail) {
Notification.error({
title: '错误信息!',
dangerouslyUseHTMLString: true,
duration: 100000,
message: `<div>
<textarea style="border:0;border-radius:5px;background-color:rgba(241,241,241,.98);width: 300px;height: 400px;padding: 10px;resize: none;position: relative;right: 36px;">
${error_title}
${error_detail}
</textarea>
</div>` // error_detail || error_title,
})
} else { // 此处做优化 只有不出错的时候才返回response
return response
}
} else { // 此处做优化 只有不出错的时候才返回response
return response
}
},
async function(error) {
hide_full_screen_loading()
// 如果返回的code中token 过期了则刷新token
const code = error.response && error.response.status
const resData = (error.response && error.response.data) || {}
if (code === 401 && resData.error_type === 'expired' && self !== top) { // 401时过期了把请求缓存起来,等待webframe刷新token后再统一请求!
return httpClient.tokenModule.hand401Meaage(error.response.config)
} else {
response_error_del(error)
return Promise.reject(error)
}
}
)
function dyncInnerErrorDel(error) {
if (error.message === 'Network Error') {
Notification.error({
title: '错误信息!',
message: '网络连接错误!请检查您的网络是否正常!',
type: 'warning'
})
}
if (error.response && typeof error.response.data === 'string') {
Notification.error({
title: '错误信息!',
dangerouslyUseHTMLString: true,
type: 'warning',
duration: 100000,
message: `<div>
<textarea style="border:0;border-radius:5px;background-color:rgba(241,241,241,.98);width: 300px;height: 400px;padding: 10px;resize: none;position: relative;right: 36px;">
${error.response.data}
</textarea>
</div>`
})
}
if (error.response && typeof error.response.data === 'object') {
const { error_detail, error_title } = error.response.data
Notification.error({
title: '错误信息!',
dangerouslyUseHTMLString: true,
duration: 100000,
message: `<div>
<textarea style="border:0;border-radius:5px;background-color:rgba(241,241,241,.98);width: 300px;height: 400px;padding: 10px;resize: none;position: relative;right: 36px;">
${error_title}
${error_detail}
</textarea>
</div>`
})
}
}
function response_error_del(error) {
const { response, code } = error
const { status, statusText, data } = response || {}
let error_title = '错误信息'
let error_detail = ''
if (!response && !code) {
// 没网的情况
error_title = '网络连接失败,请检查网络!'
error_detail = '尝试关闭网站重新登陆!'
} else if (code === 'ECONNABORTED') {
error_title = '请求超时ECONNABORTED'
error_detail = 'Uncaught (in promise) Error: timeout of 60000ms exceeded'
} else if (status === 504) {
error_title = '请求超时504'
error_detail = data
} else if (status === 404) {
error_title = '404资源请求路径找不到'
error_detail = response.request.responseURL
} else if (status === 401 && statusText === 'UNAUTHORIZED') {
if (self !== top) parent.postMessage('login', '*')
sessionStorage.removeItem('header')
error_detail = 'UNAUTHORIZED-未授权401'
error_title = '身份验证失败,请重新登录!'
} else {
if (data.message) {
error_title = data.message
} else if (data instanceof Blob) {
// 这条判断是解决 下载文件返回流的情况 要把流转成json
const reader = new FileReader()
reader.readAsText(data)
const dealFileReader = async function() {
const result = await new Promise(function(resolve, reject) {
reader.onload = e => {
resolve(JSON.parse(e.target.result))
}
})
error_title = result.error_title ? result.error_title : '服务器异常'
error_detail = result.error_detail
if (sessionStorage['platform']) {
store.commit('set_error_info', { error_title, error_detail })
} else {
hsUtil.IframeMessage.sendErrorToWebframe({ error_title, error_detail })
}
}
dealFileReader()
return
} else if (Object.keys(data).length === 4) {
error_title = data.error_title ? data.error_title : '服务器异常'
error_detail = data.error_detail
} else {
error_title = '服务器内部错误'
error_detail = data
}
}
if (sessionStorage['platform'] || top === self) {
store.commit('set_error_info', { error_title, error_detail })
} else {
hsUtil.IframeMessage.sendErrorToWebframe({ error_title, error_detail })
}
}
axios.interceptors.request.use(
async config => {
// 设置token信息
// config.headers['refreshToken'] = sessionStorage['refresh_token']
config.headers['Authorization'] = sessionStorage['token']
config.headers['tenant'] = 'wms'
if (config.url.indexOf('no_loading') !== -1) {
} else {
if (config.url.startsWith('http:') || config.url.startsWith('https:')) {
// 俺啥都不干
} else {
config.url = config.url.replace('//', '/')
}
show_full_screen_loading()
}
if (config.url.includes('?&')) {
config.url = config.url.replace('?&', '?')
}
return config
},
err => {
hide_full_screen_loading()
return Promise.reject(err)
}
)
import { TOOL_PROXY, GQL_PROXY, COMMON_UTIL_PROXY } from './commonProxy'
export const WEB_QUERY = `${TOOL_PROXY}/web_query/`
export const WEB_QUERY_QUERY = `${TOOL_PROXY}/web_query/query/`
export const WEB_QUERY_QUERY_VALUE = `${TOOL_PROXY}/web_query/query_value/`
export const WEB_QUERY_PAGE = `${TOOL_PROXY}/web_chart_config/query_page/`
export const SQL_GQL = `${GQL_PROXY}/sql_gql/`
export const SQL_GQL_SAVE = `${GQL_PROXY}/sql_gql/save/`
export const TOOL_API = `${TOOL_PROXY}/api/`
// 单据流
export const AUDIT_BILLS = `${COMMON_UTIL_PROXY}/audit_bills/`
export const UN_AUDIT_BILLS = `${COMMON_UTIL_PROXY}/un_audit_bills/`
export const CLOSE_BILLS = `${COMMON_UTIL_PROXY}/close_bills/`
export const UN_CLOSE_BILLS = `${COMMON_UTIL_PROXY}/un_close_bills/`
export const SEND_BILLS = `${COMMON_UTIL_PROXY}/send_bills/`
export const UN_SEND_BILLS = `${COMMON_UTIL_PROXY}/un_send_bills/`
export const REJECT_BILLS = `${COMMON_UTIL_PROXY}/reject_bills/`
export const OAUTH_PROXY = 'OAUTH_PROXY'// `http://${api}/HSRight/api/`
export const TOOL_PROXY = 'TOOL_PROXY' // `http://${api}/Tool/api/`
export const HSRIGHT_TOOL_PROXY = 'HSRIGHT_TOOL_PROXY'// `http://${api}/HSRightTool/api/`
export const COMMON_UTIL_PROXY = 'COMMON_UTIL_PROXY' // `http://${api}/CommonUtil/api/`
export const COMMON_PROXY = 'COMMON_PROXY' // `http://${api}/`
export const GQL_PROXY = 'GQL_PROXY'// `http://${api}/GQL/api/`
export const FILE_RESOURCE_PROXY = 'FILE_RESOURCE_PROXY'// `http://${api}/fileresource/api/`
import { AUDIT_BILLS, UN_AUDIT_BILLS, CLOSE_BILLS, UN_CLOSE_BILLS, SEND_BILLS, UN_SEND_BILLS, REJECT_BILLS } from '../common/commonModule'
// 单据流类
class Billflow {
constructor(requestClient) {
this.requestClient = requestClient
this.moduleName = 'BillflowModule'
}
billHandleCommon(obj) {
const { data, type } = obj
let url = ''
switch (type) {
case 'billAudit':
url = `${AUDIT_BILLS}`
break
case 'billUnAudit':
url = `${UN_AUDIT_BILLS}`
break
case 'billSend':
url = `${SEND_BILLS}`
break
case 'billUnSend':
url = `${UN_SEND_BILLS}`
break
case 'billClose':
url = `${CLOSE_BILLS}`
break
case 'billUnClose':
url = `${UN_CLOSE_BILLS}`
break
case 'billReject':
url = `${REJECT_BILLS}`
break
}
return this.requestClient.post(url, data)
}
}
export default Billflow
import { COMMON_UTIL_PROXY } from '../common/commonProxy'
class Ref {
constructor(requestClient) {
this.moduleName = 'RefModule'
this.requestClient = requestClient
}
refItems(constId, parms) {
const url = `${COMMON_UTIL_PROXY}/ref/items/${constId}/`
return this.requestClient.get(url, parms)
}
refTable(tableName, columns, parms) {
const url = `${COMMON_UTIL_PROXY}/ref/table/${tableName}/${columns}/`
return this.requestClient.get(url, parms)
}
}
export default Ref
import { TOOL_API } from '../common/commonModule'
class RestFul {
constructor(requestClient) {
this.requestClient = requestClient
this.moduleName = 'RestFulModule'
}
query(data) {
const { tableName, appCode, group, parms, bodyData } = data
let url = `${TOOL_API}${appCode}/${tableName}/`
if (group) { // 非标准保存
url = `${url}${group}/`
}
if (bodyData) {
return this.requestClient.pust(url, bodyData, parms)
} else {
return this.requestClient.get(url, parms)
}
}
save(data) {
const { tableName, appCode, bodyData, group, parms } = data
let url = `${TOOL_API}${appCode}/${tableName}/`
if (group) { // 非标准保存
url = `${url}${group}/`
}
return this.requestClient.post(url, bodyData, parms)
}
queryOne(data) {
const { tableName, id, appCode, parms, group, bodyData } = data
let url_ = `${TOOL_API}${appCode}/${tableName}/${id}/`
if (group) {
url_ = `${url_}${group}/`
}
if (bodyData) {
return this.requestClient.put(url_, bodyData, parms)
} else {
return this.requestClient.get(url_, parms)
}
}
put(data) {
const { tableName, appCode, bodyData, group, parms } = data
let url = `${TOOL_API}${appCode}/${tableName}/`
if (group) { // 非标准保存
url = `${url}${group}/`
}
return this.requestClient.put(url, bodyData, parms)
}
queryList(data) {
const { tableName, appCode, parms, group, bodyData } = data
let url_ = `${TOOL_API}${appCode}/${tableName}/`
if (group) {
url_ = `${url_}${group}/`
}
parms.fuzzy = 1
if (bodyData) {
return this.requestClient.put(url_, bodyData, parms)
} else {
return this.requestClient.get(url_, parms)
}
}
deleteList(data) {
const { tableName, appCode, bodyData, parms } = data
const url_ = `${TOOL_API}${appCode}/${tableName}/`
return this.requestClient.delete(url_, bodyData, parms)
}
}
export default RestFul
import { TOOL_PROXY, FILE_RESOURCE_PROXY } from '../common/commonProxy'
class System {
constructor(requestClient, restfulClient) {
this.moduleName = 'SystemModule'
this.requestClient = requestClient
this.restfulClient = restfulClient
}
// 获取number个id
getNewId (number = 100) {
return this.requestClient.get(`${TOOL_PROXY}/common/new_id/${number}/`)
}
// 获取 动态中的action列表
queryBillpbWebDyncCode (data) {
const { appCode, pageName } = data
const params = {
parms: {
app_code: appCode,
page_name: pageName,
usable: 1
},
appCode: 'queryBi',
tableName: 'pbWebDyncCode'
}
return this.restfulClient.query(params)
}
// 获取 动态中的action列表
saveBillpbWebDyncCode (data) {
const params = {
bodyData: data,
appCode: 'queryBi',
tableName: 'pbWebDyncCode'
}
return this.restfulClient.save(params)
}
// 打印
printTask (data) {
const url = `${TOOL_PROXY}/common/print_task/`
return this.requestClient.post(url, data)
}
typePrintTask (data) {
const url = `${TOOL_PROXY}/common/print_task_by_bill_type/`
return this.requestClient.post(url, data)
}
// 上传文件
uploadFile (formData, app_code, tenant_code, config = {}) {
const parms = {
tenant_code
}
return this.requestClient.post(`${FILE_RESOURCE_PROXY}/file/${app_code}/`, formData, parms, null, config)
}
importExcel (data) {
data.group = 'import_excel'
return this.restfulClient.save(data)
}
exportExcelData (data) {
data.group = 'ExportExcel'
return this.restfulClient.queryList(data)
}
}
export default System
import jwtDecode from 'jwt-decode'
const fefresh_token_api = '/OAUTH_PROXY/token/fresh_token/'
const token_api = '/OAUTH_PROXY/token/'
class Token {
constructor(requestClient) {
this.moduleName = 'tokenModule'
this.subscribers = []
this.isRefreshing = false
this.requestClient = requestClient
// 监听消息webframe 发来的消息 设置token 并且刷新队列
window.addEventListener('message', (e) => {
if (self === top) return
if (!e.data) return
var type = e.data.type
var data = e.data.data
if (type === 'setToken') {
console.log('设置webframe传递过来的token', data)
// 设置token
this.setIframeToken(data)
// 通知本页面的请求重新请求
this.onAccessTokenFetched(data.token)
// 解决弹出框里面的iframe过期问题
this.notifyChildUpdateToken()
}
}, false)
}
setIframeToken(data) {
var token = data.token
sessionStorage['token'] = token
sessionStorage['refresh_token'] = data.refresh_token
}
// 恢复状态
cleanStatus() {
this.isRefreshing = false
this.subscribers = []
}
// 刷新token
async fefreshToken(token = sessionStorage['refresh_token']) {
const result = await this.requestClient.post(fefresh_token_api, {
refresh_token: token
})
const { access_token, token_type, refresh_token } = result.data
sessionStorage['refresh_token'] = refresh_token
sessionStorage['token'] = token_type + ' ' + access_token
return result
}
// 把当前请求推入到数组中存储起来
addSubscriber(callback) {
this.subscribers.push(callback)
}
// token刷新成功后 把存储起来的请求执行一次
onAccessTokenFetched(token) {
this.subscribers.forEach((callback) => {
callback(token)
})
this.cleanStatus()
}
async getToken() {
const result = await this.requestClient.post(token_api, {
'username': 'huansi',
'password': 'huansi',
company_code: 'hnchishan',
'company_id': '11',
'company_name': ''
}, {
tenant: 'wms',
type: '1'
})
}
// 处理401函数
hand401Meaage(config) {
if (!this.isRefreshing) {
this.isRefreshing = true
top.postMessage({
type: 'freshToken'
}, '*')
}
// 这个Promise函数很关键
const retryOriginalRequest = new Promise((resolve) => {
this.addSubscriber(() => {
resolve(this.requestClient.requestConfig(config))
})
})
return retryOriginalRequest
}
// 处理401函数
hand401MeaageWebframe(config) {
if (!this.isRefreshing) {
// 异步处理 token刷新成功后把缓存的请求全部刷新
this.fefreshToken().then(res => {
this.onAccessTokenFetched(res)
})
}
// 这个Promise函数很关键
const retryOriginalRequest = new Promise((resolve) => {
this.addSubscriber(() => {
resolve(this.requestClient.requestConfig(config))
})
})
return retryOriginalRequest
}
// 判断token是否过期
checkTokenExpire() {
const BearerToken = sessionStorage['token']
if (!BearerToken) return true
const access_token = BearerToken.slice(7, BearerToken.length)
const decodeTokenInfo = jwtDecode(access_token)
const { exp } = decodeTokenInfo
const now = Math.round(new Date() / 1000)
return now - exp > 0
}
// 判断过期自动刷新
async checkTokenRefreshToken() {
const resultCheck = this.checkTokenExpire()
if (resultCheck) {
await this.fefreshToken()
}
}
// 更新子iframe
async updateChildIframeToken() {
const resultCheck = this.checkTokenExpire()
if (resultCheck) {
await this.fefreshToken()
this.notifyChildUpdateToken()
}
}
notifyChildUpdateToken() {
const refresh_token = sessionStorage['refresh_token']
const token = sessionStorage['token']
const iframes = Array.from(document.getElementsByTagName('iframe'))
iframes.forEach(item => {
this.postMessageBycontentWindow(item.contentWindow, {
type: 'setToken',
data: {
refresh_token: refresh_token,
token: token
}
})
})
}
postMessageBycontentWindow(contentWindow, message) {
contentWindow.postMessage(message, '*')
}
}
export default Token
import { WEB_QUERY, WEB_QUERY_QUERY, WEB_QUERY_QUERY_VALUE, WEB_QUERY_PAGE } from '../common/commonModule'
import hsUtil from 'hs-util-js'
const urlParam = hsUtil.System.getUrlParams()
const { user_id } = hsUtil.System.parseGlobalParams()
class Control {
constructor(requestClient) {
this.requestClient = requestClient
this.moduleName = 'WebChartConfigModule'
}
// 处理传入的data 如果有appCode,pageName dbName
packParamHandle(parms) {
const { appCode, pageName, dbName, dbCode, userId } = parms
if (!appCode) {
parms.appCode = urlParam.appCode
}
if (!pageName) {
parms.pageName = urlParam.pageName
}
if (!dbName) {
parms.dbName = urlParam.dbName || ''
}
if (!dbCode) {
parms.dbCode = urlParam.dbCode || ''
}
if (!userId) {
parms.userId = user_id || 1
}
}
// 保存控件配置
/**
* sAppCode:页面appCode
* sPage:页面名称
* sControl:控件名称
* sControlType: 类型
* sQuerySql: sql语句
* bMockData: 是否是模拟数据
* iUserId:用户id
* db_name: 数据库名
* db_code:数据库code
* sConfig:控件配置
* sData: 数据
* @param {*} data
*/
webChartConfigSave(param) { // routerParms: page路由 position位置 other参数, sConfig 配置json sData 数据json
this.packParamHandle(param)
const { appCode, pageName, controlName, controlType, querySql, mockData, userId, dbName, dbCode, config, data } = param
const postData = {
exec_sql: `EXEC dbo.spappWebChartConfig_Save @sAppCode='${appCode}',@sPage='${pageName}',@sControl='${controlName}',@sControlType='${controlType || ''}',@sConfig=:sConfig,@sData=:sData,@sQuerySql='${querySql || ''}',@bMockData='${mockData || ''}',@iUserId=${userId || 1}`,
db_name: dbName,
db_code: dbCode,
param: {
sConfig: JSON.stringify(config),
sData: JSON.stringify(data)
}
}
return this.requestClient.post(WEB_QUERY, postData)
}
// 查询配置
/**
* sAppCode:页面appCode
* sPage:页面名称
* sControl:控件名称
* sControlType: 类型
* sQuerySql: sql语句
* bMockData: 是否是模拟数据
* iUserId:用户id
* db_name: 数据库名
* db_code:数据库code
* sConfig:控件配置
* sData: 数据
* @param {*} data
*/
webChartConfigQuery(data) {
this.packParamHandle(data)
const { appCode, pageName, controlName, userId, dbName, dbCode } = data
const postData = {
exec_sql: `EXEC dbo.spappWebChartConfig_Query @sAppCode='${appCode}',@sPage='${pageName}',@sControl='${controlName}',@iUserId='${userId}'`,
db_name: dbName,
db_code: dbCode
}
return this.requestClient.post(WEB_QUERY_QUERY, postData)
}
// 获取将要另存到本地的配置
webChartConfigSaveAs(data) {
this.packParamHandle(data)
const { appCode, pageName, dbName, dbCode } = data
const postData = {
exec_sql: `EXEC dbo.spappWebChartConfig_SaveAs @sAppCode='${appCode}',@sPage='${pageName}'`,
db_name: dbName,
db_code: dbCode
}
return this.requestClient.post(WEB_QUERY_QUERY_VALUE, postData)
}
// 另存配置
async saveAsDataToLocal(data) {
this.packParamHandle(data)
const { appCode, pageName } = data
const res = await this.webChartConfigSaveAs(data)
if (!res) return
this.download(`spappWebChartConfig_Upgrade_${appCode}_${pageName}.sql`, res.data)
}
download(name, data) {
var urlObject = window.URL || window.webkitURL || window
var downloadData = new Blob([data])
var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a')
save_link.href = urlObject.createObjectURL(downloadData)
save_link.download = name
this.fake_click(save_link)
}
fake_click(obj) {
var ev = document.createEvent('MouseEvents')
ev.initMouseEvent(
'click', true, false, window, 0, 0, 0, 0, 0
, false, false, false, false, 0, null
)
obj.dispatchEvent(ev)
}
// 直接执行sql语句
execSql(data) {
this.packParamHandle(data)
const { execSql, dbName, dbCode } = data
const postData = {
exec_sql: execSql,
db_name: dbName,
db_code: dbCode
}
return this.requestClient.post(WEB_QUERY_QUERY, postData)
}
webChartConfigQueryLog(data) {
this.packParamHandle(data)
const { appCode, pageName, controlName, dbName, dbCode } = data
const postData = {
exec_sql: `EXEC dbo.spappWebChartConfig_QueryLog @sAppCode='${appCode}',@sPageName='${pageName}',@sControlName='${controlName}'`,
db_name: dbName,
db_code: dbCode
}
return this.requestClient.post(WEB_QUERY_QUERY, postData)
}
webChartConfigRevert(data) {
this.packParamHandle(data)
const { appCode, pageName, dbName, dbCode, controlName, version } = data
const postData = {
exec_sql: `EXEC dbo.spappWebChartConfig_Revert @sAppCode='${appCode}',@sPageName='${pageName}',@sControlName='${controlName}',@iVersion='${version}'`,
db_name: dbName,
db_code: dbCode
}
return this.requestClient.post(WEB_QUERY, postData)
}
// 控件配置查询
webControlQuery(data) {
this.packParamHandle(data)
const { dbName, pageName, param, appCode, controlName, returnType, dbCode, userId } = data
const postData = {
db_name: dbName,
app_code: appCode,
page: pageName,
param: JSON.stringify(param || {}),
control_name: controlName,
return_type: returnType || 3,
db_code: dbCode,
user_id: userId
}
return this.requestClient.post(WEB_QUERY_PAGE, postData)
}
}
export default Control
import { WEB_QUERY_QUERY, WEB_QUERY_PAGE } from '../common/commonModule'
class WebQuery {
constructor(requestClient) {
this.requestClient = requestClient
this.moduleName = 'webQuery'
}
webQuery(data, params, header) {
return this.requestClient.post(WEB_QUERY_QUERY, data, params, header)
}
queryPage(data, params, header) {
return this.requestClient.post(WEB_QUERY_PAGE, data, params, header)
}
}
export default WebQuery
import axios from 'axios'
class Root {
filterEmptyValue(obj) {
if (!obj) return
const emptyValues = [null, undefined, 'null', 'undefined', NaN]
for (const k in obj) {
if (emptyValues.includes(obj[k])) {
console.log(`数据中有空值${k}`, obj[k])
delete obj[k]
} else if (typeof obj[k] === 'object') {
return this.filterEmptyValue(obj[k])
}
}
}
get(url, params, headers, config) {
return this.request('get', url, null, params, headers, config)
}
post(url, data, params, headers, config) {
return this.request('post', url, data, params, headers, config)
}
put(url, data, params, headers, config) {
return this.request('put', url, data, params, headers, config)
}
delete(url, data, params, headers, config) {
return this.request('delete', url, data, params, headers, config)
}
requestConfig(config) {
return axios(config)
}
request(method, url, data, params, headers = null, config = {}) {
this.filterEmptyValue(data)
// 公共头设置
const aixosCtx = { method, url, ...config }
params && (aixosCtx.params = params)
if (aixosCtx.params && aixosCtx.params.token) delete aixosCtx.params.token
if (aixosCtx.params && aixosCtx.params._user_info) delete aixosCtx.params._user_info
data && (aixosCtx.data = data)
headers && (aixosCtx.headers = headers)
const result = axios(aixosCtx)
return result
}
}
export default Root
import Root from './root'
import Billflow from './packages/modules/billflow'
import WebChartConfig from './packages/modules/webChartConfig'
import Restful from './packages/modules/restful'
import System from './packages/modules/system'
import TokenTool from './packages/modules/tokenTool'
import WebQueryClient from './packages/modules/webQueryClient'
import Ref from './packages/modules/ref'
const root = new Root()
const restful = new Restful(root)
const webQueryClient = new WebQueryClient(root)
const billflow = new Billflow(root)
const system = new System(root, restful)
const tokenTool = new TokenTool(root)
const webChartConfig = new WebChartConfig(root)
const ref = new Ref(root)
const list = [webQueryClient, billflow, system, tokenTool, webChartConfig, restful, ref]
const api = {
}
list.forEach(item => {
api[item.moduleName] = item
})
const root_prototype = root.__proto__
const root_prototype_keys = Object.getOwnPropertyNames(root_prototype)
root_prototype_keys.forEach(k => {
if (k !== 'constructor') {
api[`${k}`] = root_prototype[k]
}
})
export default api
import Vue from 'vue'
import ElementUI from 'element-ui'
Vue.use(ElementUI)
import 'element-ui/lib/theme-chalk/index.css'
const requireComponent_ = require.context('./', true, /index.vue$/)
const obj = {}
const install = function(Vue) {
......@@ -16,5 +12,16 @@ const install = function(Vue) {
}
})
}
// if (typeof window !== 'undefined' && window.Vue || Vue) {
// install(window.Vue || Vue);
// }
// requireComponent_.keys().forEach(fileName => {
// const componentConfig = requireComponent_(fileName)
// const { name } = componentConfig.default
// if (name) {
// Vue.component(name, componentConfig.default || componentConfig)
// obj[name] = componentConfig
// }
// })
obj.install = install
export default obj
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment