cmvr-wms/ruoyi-ui-vue3/tests/fixtures/purchase-cell.js

20 lines
2.6 KiB
JavaScript
Raw Normal View History

// Isolated real controls: no login, business requests, saves or production data.
import { createApp, nextTick } from 'vue'
import { compile } from 'vue/dist/vue.esm-bundler.js'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import Cell from '../../src/components/PurchaseSheet/Cell.vue'
import Sheet from '../../src/components/PurchaseSheet/index.vue'
const names=['activateCell','nameMenu','nameChoices','itemLabel','currentSpec','menu','menuOpen','brands','specs','identityEditor','nameChanged','brandChanged','specChanged','mergeItems']
const methods=Object.fromEntries(names.map(name=>[name,Sheet.methods[name]]))
let choices=0
methods.nameChoices=function(row){if(++choices>300)throw new Error('nameChoices render loop: '+choices);return Sheet.methods.nameChoices.call(this,row)}
createApp({
components:{Cell},
data:()=>({row:{_key:'draft',materialName:'',materialBrand:'',materialParams:'',finalUnitPrice:null},columns:[{field:'materialName',label:'物品名称'},{field:'materialParams',label:'规格型号'},{field:'materialBrand',label:'品牌'},{field:'finalUnitPrice',label:'报价'}],items:[],nameOptions:null,nameMenuRow:null,nameLoading:false,activeMenu:null,editCell:null,saving:false,searches:0,ticks:0}),
computed:{cellOwner(){return this},nameItems(){return this.nameOptions||this.items},isEditing(){return true},sheet(){return {rows:[this.row]}}},
methods:{...methods,cellError(){return ''},editableCell(){return true},readonly(){return false},fieldLocked(){return false},displayCell(row,field){return row[field]||'—'},originalIndex(){return 0},rememberCell(){},paste(){},navigate(){},clearLoan(){},async revealRow(){await nextTick()},async loadName(){},async searchNames(keyword){this.searches++;this.nameLoading=true;await new Promise(resolve=>setTimeout(resolve,80));this.mergeItems([]);this.nameOptions=[];this.nameLoading=false}},
mounted(){this.timer=setInterval(()=>this.ticks++,200)},beforeUnmount(){clearInterval(this.timer)},
render:compile(`<main style="padding:24px"><h1>采购单元格回归测试</h1><p>仅测试输入,不保存业务数据。心跳 {{ticks}} · 搜索 {{searches}} 次</p><table border="1" cellpadding="10"><thead><tr><th v-for="c in columns">{{c.label}}</th></tr></thead><tbody><tr><td v-for="c in columns" :key="c.field" style="width:220px"><Cell :row="row" :column="c" :index="0" :owner="cellOwner" :active="editCell===row._key+'|'+c.field"/></td></tr></tbody></table><pre aria-label="草稿字段">{{JSON.stringify(row,null,2)}}</pre><button @click="ticks++">测试页面响应</button></main>`)
}).use(ElementPlus).mount('#app')