|
@@ -0,0 +1,180 @@
|
|
|
+<template>
|
|
|
+ <!-- 混合表格顶部工具栏 -->
|
|
|
+ <div class="toolbar-wrapper">
|
|
|
+ <div
|
|
|
+ class="tool-btn-item" v-for="tool in toolIcons"
|
|
|
+ :key="tool.key"
|
|
|
+ @click="dealToolHandles(tool)"
|
|
|
+ >
|
|
|
+ <button>
|
|
|
+ <!-- icon -->
|
|
|
+ <template v-if="tool.type==='icon'">
|
|
|
+ <span class="icon-wrap" v-html="tool.icon"></span>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-if="tool.type==='select'">
|
|
|
+ <el-select v-model="option.nt" style="width: 90px" size="small" v-if="tool.key==='cell-type-edit'">
|
|
|
+ <el-option
|
|
|
+ v-for="item in numberTypeOptions"
|
|
|
+ :key="item.key"
|
|
|
+ :value="item.key"
|
|
|
+ :label="item.label"
|
|
|
+ >
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+import { transDecimalPlace,isNumberVal,getDecimalPlaces } from '../common/customTable';
|
|
|
+export default {
|
|
|
+ props: {
|
|
|
+ cell: {
|
|
|
+ type: Object,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ cell(nval) {
|
|
|
+ if(nval.ShowStyle) {
|
|
|
+ this.option = {
|
|
|
+ ...JSON.parse(nval.ShowStyle)
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ this.option = {
|
|
|
+ nt: "number",//numberType
|
|
|
+ pn: 0,//ponitNum
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ option: {
|
|
|
+ nt: "number",//numberType
|
|
|
+ pn: 0,//ponitNum
|
|
|
+ },
|
|
|
+
|
|
|
+ toolIcons: [
|
|
|
+ {
|
|
|
+ icon: `<svg viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
|
+ <g id="increase-decimal" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
|
+ <g id="Increase-Decimal" transform="translate(1.000000, 1.000000)">
|
|
|
+ <polygon id="Shape" fill="#333" fill-rule="nonzero" transform="translate(3.500000, 2.500000) rotate(-270.000000) translate(-3.500000, -2.500000) " points="3.5 6 6 3.5 4 3.5 4 -1 3 -1 3 3.5 1 3.5"></polygon>
|
|
|
+ <path d="M12,0 C12.6360153,0 13.1340996,0.274932615 13.4942529,0.84097035 C13.8314176,1.37466307 14,2.09433962 14,3 C14,3.90566038 13.8314176,4.62533693 13.4942529,5.15902965 C13.1340996,5.71698113 12.6360153,6 12,6 C11.3563218,6 10.8582375,5.71698113 10.5057471,5.15902965 C10.1685824,4.62533693 10,3.90566038 10,3 C10,2.09433962 10.1685824,1.37466307 10.5057471,0.84097035 C10.8582375,0.274932615 11.3563218,0 12,0 Z M12,0.800539084 C11.5632184,0.800539084 11.256705,1.05121294 11.0804598,1.56873315 C10.9578544,1.91644205 10.8965517,2.393531 10.8965517,3 C10.8965517,3.59838275 10.9578544,4.0754717 11.0804598,4.43126685 C11.256705,4.94070081 11.5632184,5.19946092 12,5.19946092 C12.4291188,5.19946092 12.7356322,4.94070081 12.9195402,4.43126685 C13.0421456,4.0754717 13.1034483,3.59838275 13.1034483,3 C13.1034483,2.393531 13.0421456,1.91644205 12.9195402,1.56873315 C12.7356322,1.05121294 12.4291188,0.800539084 12,0.800539084 Z" id="0" fill="#333"></path>
|
|
|
+ <path d="M12,8 C12.6360153,8 13.1340996,8.27493261 13.4942529,8.84097035 C13.8314176,9.37466307 14,10.0943396 14,11 C14,11.9056604 13.8314176,12.6253369 13.4942529,13.1590296 C13.1340996,13.7169811 12.6360153,14 12,14 C11.3563218,14 10.8582375,13.7169811 10.5057471,13.1590296 C10.1685824,12.6253369 10,11.9056604 10,11 C10,10.0943396 10.1685824,9.37466307 10.5057471,8.84097035 C10.8582375,8.27493261 11.3563218,8 12,8 Z M12,8.80053908 C11.5632184,8.80053908 11.256705,9.05121294 11.0804598,9.56873315 C10.9578544,9.91644205 10.8965517,10.393531 10.8965517,11 C10.8965517,11.5983827 10.9578544,12.0754717 11.0804598,12.4312668 C11.256705,12.9407008 11.5632184,13.1994609 12,13.1994609 C12.4291188,13.1994609 12.7356322,12.9407008 12.9195402,12.4312668 C13.0421456,12.0754717 13.1034483,11.5983827 13.1034483,11 C13.1034483,10.393531 13.0421456,9.91644205 12.9195402,9.56873315 C12.7356322,9.05121294 12.4291188,8.80053908 12,8.80053908 Z" id="0-copy" fill="#333"></path>
|
|
|
+ <path d="M6,8 C6.63601533,8 7.13409962,8.27493261 7.49425287,8.84097035 C7.83141762,9.37466307 8,10.0943396 8,11 C8,11.9056604 7.83141762,12.6253369 7.49425287,13.1590296 C7.13409962,13.7169811 6.63601533,14 6,14 C5.35632184,14 4.85823755,13.7169811 4.50574713,13.1590296 C4.16858238,12.6253369 4,11.9056604 4,11 C4,10.0943396 4.16858238,9.37466307 4.50574713,8.84097035 C4.85823755,8.27493261 5.35632184,8 6,8 Z M6,8.80053908 C5.56321839,8.80053908 5.25670498,9.05121294 5.08045977,9.56873315 C4.95785441,9.91644205 4.89655172,10.393531 4.89655172,11 C4.89655172,11.5983827 4.95785441,12.0754717 5.08045977,12.4312668 C5.25670498,12.9407008 5.56321839,13.1994609 6,13.1994609 C6.42911877,13.1994609 6.73563218,12.9407008 6.91954023,12.4312668 C7.04214559,12.0754717 7.10344828,11.5983827 7.10344828,11 C7.10344828,10.393531 7.04214559,9.91644205 6.91954023,9.56873315 C6.73563218,9.05121294 6.42911877,8.80053908 6,8.80053908 Z" id="0-copy-2" fill="#333"></path>
|
|
|
+ <path d="M7.99363057,4 C8.27388535,4 8.50318471,4.08917197 8.70700637,4.29299363 C8.89808917,4.48407643 9,4.72611465 9,5.00636943 C9,5.2866242 8.89808917,5.51592357 8.70700637,5.71974522 C8.50318471,5.89808917 8.27388535,6 7.99363057,6 C7.7133758,6 7.47133758,5.89808917 7.29299363,5.71974522 C7.08917197,5.51592357 7,5.2866242 7,5.00636943 C7,4.72611465 7.08917197,4.48407643 7.29299363,4.29299363 C7.47133758,4.08917197 7.7133758,4 7.99363057,4 Z" id="." fill="#333"></path>
|
|
|
+ <path d="M0.993630573,12 C1.27388535,12 1.50318471,12.089172 1.70700637,12.2929936 C1.89808917,12.4840764 2,12.7261146 2,13.0063694 C2,13.2866242 1.89808917,13.5159236 1.70700637,13.7197452 C1.50318471,13.8980892 1.27388535,14 0.993630573,14 C0.713375796,14 0.47133758,13.8980892 0.292993631,13.7197452 C0.0891719745,13.5159236 0,13.2866242 0,13.0063694 C0,12.7261146 0.0891719745,12.4840764 0.292993631,12.2929936 C0.47133758,12.089172 0.713375796,12 0.993630573,12 Z" id=".-copy" fill="#333"></path>
|
|
|
+ </g>
|
|
|
+ </g>
|
|
|
+ </svg>`,
|
|
|
+ key: "add-point",
|
|
|
+ type: 'icon',
|
|
|
+ title: '增加小数位数'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ icon: `<svg viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
|
+ <g id="decrease-decimal" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
|
+ <g transform="translate(1.000000, 1.000000)">
|
|
|
+ <polygon id="Shape" fill="#333" fill-rule="nonzero" transform="translate(3.500000, 10.500000) rotate(-90.000000) translate(-3.500000, -10.500000) " points="3.5 14 6 11.5 4 11.5 4 7 3 7 3 11.5 1 11.5"></polygon>
|
|
|
+ <path d="M12,0 C12.6360153,0 13.1340996,0.274932615 13.4942529,0.84097035 C13.8314176,1.37466307 14,2.09433962 14,3 C14,3.90566038 13.8314176,4.62533693 13.4942529,5.15902965 C13.1340996,5.71698113 12.6360153,6 12,6 C11.3563218,6 10.8582375,5.71698113 10.5057471,5.15902965 C10.1685824,4.62533693 10,3.90566038 10,3 C10,2.09433962 10.1685824,1.37466307 10.5057471,0.84097035 C10.8582375,0.274932615 11.3563218,0 12,0 Z M12,0.800539084 C11.5632184,0.800539084 11.256705,1.05121294 11.0804598,1.56873315 C10.9578544,1.91644205 10.8965517,2.393531 10.8965517,3 C10.8965517,3.59838275 10.9578544,4.0754717 11.0804598,4.43126685 C11.256705,4.94070081 11.5632184,5.19946092 12,5.19946092 C12.4291188,5.19946092 12.7356322,4.94070081 12.9195402,4.43126685 C13.0421456,4.0754717 13.1034483,3.59838275 13.1034483,3 C13.1034483,2.393531 13.0421456,1.91644205 12.9195402,1.56873315 C12.7356322,1.05121294 12.4291188,0.800539084 12,0.800539084 Z" id="0" fill="#333"></path>
|
|
|
+ <path d="M12,8 C12.6360153,8 13.1340996,8.27493261 13.4942529,8.84097035 C13.8314176,9.37466307 14,10.0943396 14,11 C14,11.9056604 13.8314176,12.6253369 13.4942529,13.1590296 C13.1340996,13.7169811 12.6360153,14 12,14 C11.3563218,14 10.8582375,13.7169811 10.5057471,13.1590296 C10.1685824,12.6253369 10,11.9056604 10,11 C10,10.0943396 10.1685824,9.37466307 10.5057471,8.84097035 C10.8582375,8.27493261 11.3563218,8 12,8 Z M12,8.80053908 C11.5632184,8.80053908 11.256705,9.05121294 11.0804598,9.56873315 C10.9578544,9.91644205 10.8965517,10.393531 10.8965517,11 C10.8965517,11.5983827 10.9578544,12.0754717 11.0804598,12.4312668 C11.256705,12.9407008 11.5632184,13.1994609 12,13.1994609 C12.4291188,13.1994609 12.7356322,12.9407008 12.9195402,12.4312668 C13.0421456,12.0754717 13.1034483,11.5983827 13.1034483,11 C13.1034483,10.393531 13.0421456,9.91644205 12.9195402,9.56873315 C12.7356322,9.05121294 12.4291188,8.80053908 12,8.80053908 Z" id="0-copy" fill="#333"></path>
|
|
|
+ <path d="M6,0 C6.63601533,0 7.13409962,0.274932615 7.49425287,0.84097035 C7.83141762,1.37466307 8,2.09433962 8,3 C8,3.90566038 7.83141762,4.62533693 7.49425287,5.15902965 C7.13409962,5.71698113 6.63601533,6 6,6 C5.35632184,6 4.85823755,5.71698113 4.50574713,5.15902965 C4.16858238,4.62533693 4,3.90566038 4,3 C4,2.09433962 4.16858238,1.37466307 4.50574713,0.84097035 C4.85823755,0.274932615 5.35632184,0 6,0 Z M6,0.800539084 C5.56321839,0.800539084 5.25670498,1.05121294 5.08045977,1.56873315 C4.95785441,1.91644205 4.89655172,2.393531 4.89655172,3 C4.89655172,3.59838275 4.95785441,4.0754717 5.08045977,4.43126685 C5.25670498,4.94070081 5.56321839,5.19946092 6,5.19946092 C6.42911877,5.19946092 6.73563218,4.94070081 6.91954023,4.43126685 C7.04214559,4.0754717 7.10344828,3.59838275 7.10344828,3 C7.10344828,2.393531 7.04214559,1.91644205 6.91954023,1.56873315 C6.73563218,1.05121294 6.42911877,0.800539084 6,0.800539084 Z" id="0-copy-2" fill="#333"></path>
|
|
|
+ <path d="M7.99363057,12 C8.27388535,12 8.50318471,12.089172 8.70700637,12.2929936 C8.89808917,12.4840764 9,12.7261146 9,13.0063694 C9,13.2866242 8.89808917,13.5159236 8.70700637,13.7197452 C8.50318471,13.8980892 8.27388535,14 7.99363057,14 C7.7133758,14 7.47133758,13.8980892 7.29299363,13.7197452 C7.08917197,13.5159236 7,13.2866242 7,13.0063694 C7,12.7261146 7.08917197,12.4840764 7.29299363,12.2929936 C7.47133758,12.089172 7.7133758,12 7.99363057,12 Z" id="." fill="#333"></path>
|
|
|
+ <path d="M0.993630573,4 C1.27388535,4 1.50318471,4.08917197 1.70700637,4.29299363 C1.89808917,4.48407643 2,4.72611465 2,5.00636943 C2,5.2866242 1.89808917,5.51592357 1.70700637,5.71974522 C1.50318471,5.89808917 1.27388535,6 0.993630573,6 C0.713375796,6 0.47133758,5.89808917 0.292993631,5.71974522 C0.0891719745,5.51592357 0,5.2866242 0,5.00636943 C0,4.72611465 0.0891719745,4.48407643 0.292993631,4.29299363 C0.47133758,4.08917197 0.713375796,4 0.993630573,4 Z" id=".-copy" fill="#333"></path>
|
|
|
+ </g>
|
|
|
+ </g>
|
|
|
+ </svg>`,
|
|
|
+ key: "del-point",
|
|
|
+ type: 'icon',
|
|
|
+ title: '减少小数位数'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ icon: '',
|
|
|
+ key: 'cell-type-edit',
|
|
|
+ type:'select',
|
|
|
+ title:''
|
|
|
+ }
|
|
|
+ ],
|
|
|
+
|
|
|
+ numberTypeOptions: [
|
|
|
+ { label: "数字", key: "number" },
|
|
|
+ { label: "百分位", key: "percent" },
|
|
|
+ ],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ dealToolHandles({key}) {
|
|
|
+ //单元格不是数字就不用转了
|
|
|
+ if(!isNumberVal(this.cell.ShowValue)) return
|
|
|
+
|
|
|
+ const handlesMap = {
|
|
|
+ 'add-point': this.changeCellPoint,
|
|
|
+ 'del-point': this.changeCellPoint,
|
|
|
+ 'cell-type-edit': this.changeCellType,
|
|
|
+ }
|
|
|
+
|
|
|
+ handlesMap[key]&&handlesMap[key](key)
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 处理小数点位数 */
|
|
|
+ changeCellPoint(key) {
|
|
|
+ let value = _.cloneDeep(this.cell.ShowValue)
|
|
|
+ key==='add-point' ? this.option.pn++ : this.option.pn--;
|
|
|
+
|
|
|
+ //判断小数点后尾数 整数最小pn为0 小数最小为负位数
|
|
|
+ if(this.option.pn <= parseInt(`-${getDecimalPlaces(value)}`)) {
|
|
|
+ this.option.pn = parseInt(`-${getDecimalPlaces(value)}`)
|
|
|
+ }
|
|
|
+
|
|
|
+ let nval = transDecimalPlace(value,this.option.pn)
|
|
|
+
|
|
|
+ console.log({
|
|
|
+ ShowStyle: JSON.stringify(this.option),
|
|
|
+ ShowFormulaValue: nval
|
|
|
+ })
|
|
|
+ this.$emit('updateCell',{
|
|
|
+ ShowStyle: JSON.stringify(this.option),
|
|
|
+ ShowFormulaValue: nval
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /* 处理显示格式 */
|
|
|
+ changeCellType() {
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style scoped lang="scss">
|
|
|
+.toolbar-wrapper {
|
|
|
+ width: fit-content;
|
|
|
+ display: flex;
|
|
|
+ overflow: hidden;
|
|
|
+ background: #fff;
|
|
|
+ border: 1px solid #ccc;
|
|
|
+ padding: 4px 12px;
|
|
|
+ margin: 10px 0;
|
|
|
+ .tool-btn-item {
|
|
|
+ margin: 5px;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ button {
|
|
|
+ border: none;
|
|
|
+ padding: 4px;
|
|
|
+ background: #fff;
|
|
|
+ &:hover {
|
|
|
+ background: #ccc;
|
|
|
+ }
|
|
|
+
|
|
|
+ .icon-wrap {
|
|
|
+ width: 20px;
|
|
|
+ height: 20px;
|
|
|
+ display: inline-block;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|