add typescript definition file

This commit is contained in:
郑茂强 2018-10-12 14:49:23 +08:00
parent afa11720ee
commit 524bdc2e98
4 changed files with 228 additions and 138 deletions

View File

@ -45,11 +45,23 @@
<button @click="backToDesignTemplate">返回我的设计报表</button> <button @click="backToDesignTemplate">返回我的设计报表</button>
</div> </div>
<div> <div>
<h2>标签</h2> <h4>订单标签</h4>
<ul> <ul>
<li v-for="(tag,index) of tags" @click="tagClickHandler(tag)" :key="index">{{tag}}</li> <li v-for="(tag,index) of orderTags" @click="tagClickHandler(tag)" :key="index">{{tag}}</li>
</ul> </ul>
<h4>板材头部标签</h4>
<ul>
<li v-for="(tag,index) of banCaiHeadTags" @click="tagClickHandler(tag)" :key="index">{{tag}}</li>
</ul>
<h4>板材身体标签</h4>
<ul>
<li v-for="(tag,index) of banCaiBodyTags" @click="tagClickHandler(tag)" :key="index">{{tag}}</li>
</ul>
<h4>其他标签</h4>
<ul>
<li v-for="(tag,index) of otherTags" @click="tagClickHandler(tag)" :key="index">{{tag}}</li>
</ul>
</div> </div>
<div> <div>
@ -89,6 +101,7 @@ import reportCell from './reportCell.vue';
import { Tool } from '@/components/reportTemplate/rescource/methodTool'; import { Tool } from '@/components/reportTemplate/rescource/methodTool';
import { hightlight } from '@/components/reportTemplate/rescource/hightlight'; import { hightlight } from '@/components/reportTemplate/rescource/hightlight';
import * as TypeDefinition from '@/components/reportTemplate/rescource/tyscriptDefinition';
let rowId = 30; // this figure is for testing use let rowId = 30; // this figure is for testing use
let cellId = 9060; // this figure is for testing use let cellId = 9060; // this figure is for testing use
@ -123,46 +136,7 @@ const banCaiBodyTags = [
export default Vue.extend({ export default Vue.extend({
components: { reportCell }, components: { reportCell },
data(): { data(): TypeDefinition.Data {
infos: Array<{
rowId: number;
rowTitle: string;
cells: Array<{
cellId: number;
title: string;
colspan: number;
height: number;
textAlign: string;
fontSize: number;
fontStyle: string;
}>;
}>;
data: any;
selectedRow: number;
selectedCell: number;
inputTitle: string;
inputColspan: number;
inputHeight: number;
textAlign: string;
fontSize: number;
fontStyle: string;
recordHistory: string[];
importedData: any;
currentCell: {
cellId: number;
title: string;
colspan: number;
height: number;
textAlign: string;
fontSize: number;
fontStyle: string;
};
banCaiHeadStartLineIndex: string;
banCaiHeadEndLineIndex: string;
tags: string[];
designTemplate: any;
} {
return { return {
infos: startUpRowColumn, infos: startUpRowColumn,
data, data,
@ -187,7 +161,7 @@ export default Vue.extend({
}, },
banCaiHeadStartLineIndex: '5', banCaiHeadStartLineIndex: '5',
banCaiHeadEndLineIndex: '8', banCaiHeadEndLineIndex: '8',
tags: [ orderTags: [
'${订单号}', '${订单号}',
'${客户名}', '${客户名}',
'${出售日期}', '${出售日期}',
@ -195,8 +169,9 @@ export default Vue.extend({
'${联系电话}', '${联系电话}',
'${送货地址}', '${送货地址}',
'${订单备注}', '${订单备注}',
'${板材材料}', ],
'${板材颜色}', banCaiHeadTags: ['${板材材料}', '${板材颜色}'],
banCaiBodyTags: [
'${板材房名}', '${板材房名}',
'${板材柜名}', '${板材柜名}',
'${板材号}', '${板材号}',
@ -212,6 +187,19 @@ export default Vue.extend({
'${条纹}', '${条纹}',
'${板材备注}', '${板材备注}',
], ],
otherTags: [
'${长度小计}',
'${宽度小计}',
'${厚度小计}',
'${数量小计}',
'${面积小计}',
'${长度总计}',
'${宽度总计}',
'${厚度总计}',
'${数量总计}',
'${面积总计}',
'${板材数量}',
],
designTemplate: 0, designTemplate: 0,
}; };
}, },
@ -310,6 +298,7 @@ export default Vue.extend({
backToDesignTemplate() { backToDesignTemplate() {
if (this.designTemplate) { if (this.designTemplate) {
this.infos = this.designTemplate; this.infos = this.designTemplate;
copiedRemaingForm = [];
} else { } else {
alert('没有保存的设计报表'); alert('没有保存的设计报表');
} }

View File

@ -1,77 +1,23 @@
import data from '@/components/reportTemplate/rescource/orderDetails'; // use data for testing use import data from '@/components/reportTemplate/rescource/orderDetails'; // use data for testing use
import * as TypeDefinition from '@/components/reportTemplate/rescource/tyscriptDefinition';
const orderDetails: { const orderDetails: TypeDefinition.OrderDetails = data;
[index: string]: string | object;
orderNo: string;
clientName: string;
soldDate: string;
contactName: string;
contactNo: string;
deliveryAddress: string;
addOn: string;
boards: Array<{
[index: string]: number | string | object;
id: number;
material: string;
color: string;
boardInfos: Array<{
houseName: string;
closetName: string;
boardNo: string;
boardName: string;
length: number;
width: number;
thickness: number;
quantity: number;
area: number;
mutation: string;
shape: string;
direction: string;
stripe: string;
boardAddOn: string;
[index: string]: number | string; const subKeyWords: TypeDefinition.SubKeyWords = {
}>; '${长度小计}': 'length',
}>; '${宽度小计}': 'width',
} = data; '${厚度小计}': 'thickness',
'${数量小计}': 'quantity',
interface BoardFormat { '${面积小计}': 'area',
id: number; };
material: string; const totalKeyWords: TypeDefinition.TotalKeyWords = {
color: string; '${长度总计}': 'length',
boardInfos: Array<{ '${宽度总计}': 'width',
houseName: string; '${厚度总计}': 'thickness',
closetName: string; '${数量总计}': 'quantity',
boardNo: string; '${面积总计}': 'area',
boardName: string; };
length: number; const tagsObject: TypeDefinition.TagsObject = {
width: number;
thickness: number;
quantity: number;
area: number;
mutation: string;
shape: string;
direction: string;
stripe: string;
boardAddOn: string;
[index: string]: number | string;
}>;
}
const subKeyWords = [
'sublength',
'subwidth',
'subthickness',
'subquantity',
'subarea',
];
const totalKeyWords = [
'totallength',
'totalwidth',
'totalthickness',
'totalquantity',
'totalarea',
];
const tagsObject: any = {
'${订单号}': 'orderNo', '${订单号}': 'orderNo',
'${客户名}': 'clientName', '${客户名}': 'clientName',
'${出售日期}': 'soldDate', '${出售日期}': 'soldDate',
@ -192,7 +138,7 @@ const Tool = {
} }
that.selectedCell = 9000; that.selectedCell = 9000;
}, },
isTagName(cellTitle: string) { isTagName: (cellTitle: string) => {
if (cellTitle.slice(0, 2) === '${') { if (cellTitle.slice(0, 2) === '${') {
return true; return true;
} else { } else {
@ -201,11 +147,11 @@ const Tool = {
}, },
addTotalAmount: (query: string) => { addTotalAmount: (query: string) => {
let total: any = 0; let total: any = 0;
const query1 = query.slice(5);
for (const board of orderDetails.boards) { for (const board of orderDetails.boards) {
for (const eachBoardInfo of board.boardInfos) { for (const eachBoardInfo of board.boardInfos) {
if (Object.keys(eachBoardInfo).indexOf(query1) !== -1) { if (Object.keys(eachBoardInfo).indexOf(query) !== -1) {
total += eachBoardInfo[query1]; total += eachBoardInfo[query];
} }
} }
} }
@ -215,13 +161,12 @@ const Tool = {
return total.toFixed(3); return total.toFixed(3);
} }
}, },
addSubAmount: (query: string, board: BoardFormat) => { addSubAmount: (query: string, board: TypeDefinition.Board) => {
let sub: any = 0; let sub: any = 0;
const query1 = query.slice(3);
for (const eachBoardInfo of board.boardInfos) { for (const eachBoardInfo of board.boardInfos) {
if (Object.keys(eachBoardInfo).indexOf(query1) !== -1) { if (Object.keys(eachBoardInfo).indexOf(query) !== -1) {
sub += eachBoardInfo[query1]; sub += eachBoardInfo[query];
} }
} }
if (Number.isInteger(sub)) { if (Number.isInteger(sub)) {
@ -230,10 +175,10 @@ const Tool = {
return sub.toFixed(3); return sub.toFixed(3);
} }
}, },
addBoardInfoAmount: (that: any, board: BoardFormat) => { addBoardInfoAmount: (that: any, board: TypeDefinition.Board) => {
for (const row of that.infos) { for (const row of that.infos) {
for (const cell of row.cells) { for (const cell of row.cells) {
if (cell.title === 'bancaiinfoamount') { if (cell.title === '${板材数量}') {
cell.title = board.boardInfos.length; cell.title = board.boardInfos.length;
} }
} }
@ -280,8 +225,8 @@ const Tool = {
} }
for (const row of that.infos) { for (const row of that.infos) {
for (const cell of row.cells) { for (const cell of row.cells) {
if (totalKeyWords.indexOf(cell.title) !== -1) { if (Object.keys(totalKeyWords).indexOf(cell.title) !== -1) {
cell.title = that.addTotalAmount(cell.title); cell.title = that.addTotalAmount(totalKeyWords[cell.title]);
} }
} }
} }
@ -310,11 +255,11 @@ const Tool = {
pasteBanCaiBody: (that: any, boardIndex: number) => { pasteBanCaiBody: (that: any, boardIndex: number) => {
const boardInfosTemplateHolder = []; const boardInfosTemplateHolder = [];
const copyBanCaiBodyTemplateIndex: any = Tool.copyBanCaiBodyTemplate(that); const BanCaiBodyTemplateIndex: any = Tool.copyBanCaiBodyTemplate(that);
for (const i of orderDetails.boards[boardIndex].boardInfos) { for (const i of orderDetails.boards[boardIndex].boardInfos) {
boardInfosTemplateHolder.push( boardInfosTemplateHolder.push(
that.copySingleRow(that.infos[copyBanCaiBodyTemplateIndex].rowId), that.copySingleRow(that.infos[BanCaiBodyTemplateIndex].rowId),
); );
} }
@ -328,10 +273,10 @@ const Tool = {
} }
} }
that.infos.splice(copyBanCaiBodyTemplateIndex, 1); that.infos.splice(BanCaiBodyTemplateIndex, 1);
for (let i = 0; i < boardInfosTemplateHolder.length; i++) { for (let i = 0; i < boardInfosTemplateHolder.length; i++) {
that.infos.splice( that.infos.splice(
copyBanCaiBodyTemplateIndex + i, BanCaiBodyTemplateIndex + i,
0, 0,
boardInfosTemplateHolder[i], boardInfosTemplateHolder[i],
); );
@ -362,8 +307,8 @@ const Tool = {
addsubQuantity: (that: any, board: any) => { addsubQuantity: (that: any, board: any) => {
for (const row of that.infos) { for (const row of that.infos) {
for (const cell of row.cells) { for (const cell of row.cells) {
if (subKeyWords.indexOf(cell.title) !== -1) { if (Object.keys(subKeyWords).indexOf(cell.title) !== -1) {
cell.title = that.addSubAmount(cell.title, board); cell.title = that.addSubAmount(subKeyWords[cell.title], board);
} }
} }
} }

View File

@ -431,7 +431,7 @@ const initialTemplateData = [
}, },
{ {
cellId: 9060, cellId: 9060,
title: 'bancaiinfoamount', title: '${板材数量}',
colspan: 4, colspan: 4,
height: 30, height: 30,
textAlign: 'left', textAlign: 'left',
@ -719,7 +719,7 @@ const initialTemplateData = [
}, },
{ {
cellId: 9048, cellId: 9048,
title: 'subquantity', title: '${数量小计}',
colspan: 14, colspan: 14,
height: 30, height: 30,
textAlign: 'left', textAlign: 'left',
@ -743,7 +743,7 @@ const initialTemplateData = [
}, },
{ {
cellId: 9050, cellId: 9050,
title: 'totalquantity', title: '${数量总计}',
colspan: 14, colspan: 14,
height: 30, height: 30,
textAlign: 'left', textAlign: 'left',

View File

@ -0,0 +1,156 @@
interface SingleInfo {
rowId: number;
rowTitle: string;
cells: Array<{
cellId: number;
title: string;
colspan: number;
height: number;
textAlign: string;
fontSize: number;
fontStyle: string;
}>;
}
interface CurrentCell {
cellId: number;
title: string;
colspan: number;
height: number;
textAlign: string;
fontSize: number;
fontStyle: string;
}
interface OrderDetails {
[index: string]: string | object;
orderNo: string;
clientName: string;
soldDate: string;
contactName: string;
contactNo: string;
deliveryAddress: string;
addOn: string;
boards: Array<{
[index: string]: number | string | object;
id: number;
material: string;
color: string;
boardInfos: Array<{
houseName: string;
closetName: string;
boardNo: string;
boardName: string;
length: number;
width: number;
thickness: number;
quantity: number;
area: number;
mutation: string;
shape: string;
direction: string;
stripe: string;
boardAddOn: string;
[index: string]: number | string;
}>;
}>;
}
interface Board {
id: number;
material: string;
color: string;
boardInfos: Array<{
houseName: string;
closetName: string;
boardNo: string;
boardName: string;
length: number;
width: number;
thickness: number;
quantity: number;
area: number;
mutation: string;
shape: string;
direction: string;
stripe: string;
boardAddOn: string;
[index: string]: number | string;
}>;
}
interface Data {
infos: Infos;
data: any;
selectedRow: number;
selectedCell: number;
inputTitle: string;
inputColspan: number;
inputHeight: number;
textAlign: string;
fontSize: number;
fontStyle: string;
recordHistory: string[];
importedData: any;
currentCell: CurrentCell;
banCaiHeadStartLineIndex: string;
banCaiHeadEndLineIndex: string;
orderTags: string[];
banCaiHeadTags: string[];
banCaiBodyTags: string[];
otherTags: string[];
designTemplate: any;
}
interface SubKeyWords {
[index: string]: string;
'${长度小计}': string;
'${宽度小计}': string;
'${厚度小计}': string;
'${数量小计}': string;
'${面积小计}': string;
}
interface TotalKeyWords {
[index: string]: string;
'${长度总计}': string;
'${宽度总计}': string;
'${厚度总计}': string;
'${数量总计}': string;
'${面积总计}': string;
}
interface TagsObject {
[index: string]: string;
'${订单号}': string;
'${客户名}': string;
'${出售日期}': string;
'${联系人}': string;
'${联系电话}': string;
'${送货地址}': string;
'${订单备注}': string;
'${板材材料}': string;
'${板材颜色}': string;
'${板材房名}': string;
'${板材柜名}': string;
'${板材号}': string;
'${板材名}': string;
'${长度}': string;
'${宽度}': string;
'${厚度}': string;
'${数量}': string;
'${面积}': string;
'${变异}': string;
'${形状}': string;
'${方向}': string;
'${条纹}': string;
'${板材备注}': string;
}
export interface Infos extends Array<SingleInfo> {}
export {
Data,
CurrentCell,
OrderDetails,
Board,
SubKeyWords,
TotalKeyWords,
TagsObject,
};