fanzhen 1209

This commit is contained in:
fanzhen123
2019-12-09 09:24:07 +08:00
parent 4666cefaec
commit 2b4a599268
20 changed files with 2152 additions and 324 deletions

View File

@@ -19,18 +19,22 @@
v-for="(item,index) in labelData"
:key="index"
:class="{bgcolor:item.state}"
@click="bgclick(index)"
@click="labelSelInd(index)"
>{{item.text}}</div>
</div>
</div>
<div class="center">
<div>=</div>
<div>></div>
<div @click="bgclick(inds)">></div>
</div>
<div class="right">
<textarea v-model="fontComput"></textarea>
<div class="computer">
<div v-for="(item,index) in computers" :key="index">{{item.text}}</div>
<div
v-for="(item,index) in computers"
:key="index"
@click="computSS(index)"
>{{item.text}}</div>
</div>
</div>
</div>
@@ -38,13 +42,14 @@
<div class="explains">说明指标只能从上表中显示</div>
<!-- 确认取消 -->
<div class="bnottom">
<div>确认</div>
<div @click="trueVerify">确认</div>
<div @click="closeX">取消</div>
</div>
</div>
</div>
</template>
<script>
import verify from '../../assets/js/verifyMathematicalExpression'
export default {
name: 'insertLabel',
data () {
@@ -90,17 +95,254 @@ export default {
{ text: '3', state: false },
{ text: '.', state: false },
{ text: '0', state: false }
]
],
// 左侧选中的指标下标
inds: false
}
},
watch: {
radioValue (newValue, oldValue) {
if (newValue === 'hang') {
// 行列新增渲染
if (this.$route.query.type === 'area') {
this.labelData = this.$store.state.transBefore.areaName
} else {
this.labelData = this.$store.state.transBefore.termsName.map((item, index) => {
return {
text: item,
state: false
}
})
}
} else if (newValue === 'lie') {
// 行列新增渲染
this.labelData = this.$store.state.transBefore.timeArr.map((item, index) => {
return {
text: item,
state: false
}
})
}
}
},
methods: {
bgclick (ind) {
labelSelInd (ind) {
this.inds = ind
this.labelData.forEach((item, index) => {
index === ind ? item.state = true : item.state = false
/*eslint-disable*/
index === ind ? (item.state = true) : item.state = false
})
},
bgclick(ind) {
console.log(ind)
if (ind !== false) {
this.labelData.forEach((item, index) => {
/*eslint-disable*/
index === ind ? (this.fontComput += '#' + item.text + '#') : ''
})
} else {
alert('请选择指标!')
}
},
closeX() {
this.$store.state.insertWindowState = false
},
// 计算器
computSS(ind) {
// console.log(ind)
// console.log(this.fontComput,'this.fontComput')
this.computers.forEach((item, index) => {
index === ind ? (item.state = true, this.fontComput += item.text) : item.state = false
})
},
closeX () {
this.$store.state.insertWindowState = false
// 确定
trueVerify() {
let Str = JSON.parse(JSON.stringify(this.fontComput)).replace(/#.*?#/gi, '$').split('')
console.log(Str, '处理成表达式')
let bty = Str.map((item, index) => {
let sft = item
if (item === '$') {
if (index === 0) {
sft = (/^[0-9]+/.test(Str[index + 1]) || /^[$]+/.test(Str[index + 1])) ? '1*' : '1'
} else if (index === Str.length - 1) {
sft = (/^[0-9]+/.test(Str[index - 1]) || /^[$]+/.test(Str[index - 1])) ? '*1' : '1'
} else {
if ((/^[$]+/.test(Str[index + 1]))) {
sft = '1*'
} else if ((/^[$]+/.test(Str[index - 1]))) {
sft = '*1'
} else {
sft = '1'
}
}
} else {
sft = item
}
return sft
})
console.log(bty.join(''))
// 验证表达式是否正确
// verify(bty.join(''), {})
if (verify(bty.join(''), {})) {
let newArrat = this.fontComput.split('#').filter((item, index) => {
return item !== ''
})
console.log(newArrat)
// 定义一个新数组用来存放新增指标的数据
let newarr = []
if (this.radioValue === 'hang') {
if (this.$route.query.type !== 'area') {
// 循环指标名称 回调一个计算后的数组
let dataStrArr = this.$store.state.transBefore.termsName.map((item, index) => {//外层
// console.log(this.$store.state.transBefore.transBeforeTermsData[index])
// 定义拼接计算的字符串
let comStr = ''
newArrat.forEach((list, key) => {
if (this.$store.state.transBefore.termsName.indexOf(list) !== -1) {
comStr += this.$store.state.transBefore.transBeforeTermsData[index][this.$store.state.transBefore.termsName.indexOf(list)]
} else {
comStr += list
}
})
// console.log(comStr)
// console.log(eval(comStr))
return eval(comStr).toString()
})
// 将处理完的数据放到全局变量中
this.$store.state.transBefore.termsName.push(this.insertName)
this.$store.state.transBefore.termsExplain.push('')
this.$store.state.transBefore.transBeforeTermsData.push(dataStrArr)
this.closeX()
this.$emit('emitState', true)
} else {
// 循环地区名称 回调一个计算后的数组
let dataStrArr = this.$store.state.transBefore.termsName.map((item, index) => {//外层
// console.log(this.$store.state.transBefore.transBeforeTermsData[index])
// 定义拼接计算的字符串
let comStr = ''
newArrat.forEach((list, key) => {
if (this.$store.state.transBefore.termsName.indexOf(list) !== -1) {
comStr += this.$store.state.transBefore.transBeforeTermsData[index][this.$store.state.transBefore.termsName.indexOf(list)]
} else {
comStr += list
}
})
// console.log(comStr)
// console.log(eval(comStr))
return eval(comStr).toString()
})
// 将处理完的数据放到全局变量中
this.$store.state.transBefore.termsName.push(this.insertName)
this.$store.state.transBefore.termsExplain.push('')
this.$store.state.transBefore.transBeforeTermsData.push(dataStrArr)
this.closeX()
this.$emit('emitState', true)
}
} else {
if (this.$route.query.type !== 'area') {
// console.log(this.$store.state.transBefore.transBeforeTermsData)
let bsfyu = this.$store.state.transBefore.transBeforeTermsData
// 将数据进行转置
let datarts = bsfyu[0].map(function (col, index) {
return bsfyu.map((row, key) => {
return row[index]
})
})
console.log(datarts)
// 循环年
let dataStrArr = this.$store.state.transBefore.timeArr.map((item, index) => {//外层
// console.log(this.$store.state.transBefore.transBeforeTermsData[index])
// 定义拼接计算的字符串
let comStr = ''
newArrat.forEach((list, key) => {
if (this.$store.state.transBefore.timeArr.indexOf(list) !== -1) {
comStr += datarts[index][this.$store.state.transBefore.timeArr.indexOf(list)]
} else {
comStr += list
}
})
// console.log(comStr)
// console.log(eval(comStr))
return eval(comStr).toString()
})
console.log(dataStrArr, '101025')
datarts.push(dataStrArr)
// 将数据转置回来
let newZz = datarts[0].map(function (col, index) {
return datarts.map((row, key) => {
return row[index]
})
})
// 将处理完的数据放到全局变量中
this.$store.state.transBefore.timeArr.push(this.insertName)
this.$store.state.transBefore.transBeforeTermsData = newZz
this.closeX()
this.$emit('emitState', true)
} else {
// console.log(this.$store.state.transBefore.transBeforeTermsData)
let bsfyu = this.$store.state.transBefore.transBeforeTermsData
// 将数据进行转置
let datarts = bsfyu[0].map(function (col, index) {
return bsfyu.map((row, key) => {
return row[index]
})
})
console.log(datarts)
// 循环年
let dataStrArr = this.$store.state.transBefore.timeArr.map((item, index) => {//外层
// console.log(this.$store.state.transBefore.transBeforeTermsData[index])
// 定义拼接计算的字符串
let comStr = ''
newArrat.forEach((list, key) => {
if (this.$store.state.transBefore.timeArr.indexOf(list) !== -1) {
comStr += datarts[index][this.$store.state.transBefore.timeArr.indexOf(list)]
} else {
comStr += list
}
})
// console.log(comStr)
// console.log(eval(comStr))
return eval(comStr).toString()
})
console.log(dataStrArr, '101025')
datarts.push(dataStrArr)
// 将数据转置回来
let newZz = datarts[0].map(function (col, index) {
return datarts.map((row, key) => {
return row[index]
})
})
// 将处理完的数据放到全局变量中
this.$store.state.transBefore.timeArr.push(this.insertName)
this.$store.state.transBefore.transBeforeTermsData = newZz
this.closeX()
this.$emit('emitState', true)
}
}
} else {
alert('您输入的表达式正确,请重新输入!')
}
}
},
mounted() {
// 行列新增渲染
if (this.$route.query.type === 'area') {
this.labelData = this.$store.state.transBefore.areaName
} else {
this.labelData = this.$store.state.transBefore.termsName.map((item, index) => {
return {
text: item,
state: false
}
})
}
}
@@ -147,7 +389,7 @@ export default {
width: 1.3125rem;
height: 1.3125rem;
}
& > img:hover{
& > img:hover {
cursor: pointer;
}
}
@@ -294,15 +536,15 @@ export default {
letter-spacing: 0rem;
}
& > div {
margin:1rem;
margin: 1rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
& > div:hover{
cursor: pointer;
}
& > div:hover {
cursor: pointer;
}
}
}
}