JEditableTable.vue 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368
  1. <!-- JEditableTable -->
  2. <!-- @version 1.5.0 -->
  3. <!-- @author sjlei -->
  4. <template>
  5. <a-spin :spinning="loading">
  6. <a-row type="flex">
  7. <a-col>
  8. <slot name="buttonBefore" :target="getVM()" />
  9. </a-col>
  10. <a-col>
  11. <!-- 操作按钮 -->
  12. <div v-if="actionButton" class="action-button">
  13. <a-button type="primary" icon="plus" @click="handleClickAdd" :disabled="disabled">插入行</a-button>
  14. <span class="gap"></span>
  15. <template v-if="selectedRowIds.length > 0">
  16. <a-popconfirm :title="`确定要移除这 ${selectedRowIds.length} 项吗?`" @confirm="handleConfirmDelete">
  17. <a-button type="primary" icon="minus" :disabled="disabled">移除行</a-button>
  18. <span class="gap"></span>
  19. </a-popconfirm>
  20. <template v-if="showClearSelectButton">
  21. <a-button icon="delete" @click="handleClickClearSelection">清空选择</a-button>
  22. <span class="gap"></span>
  23. </template>
  24. </template>
  25. </div>
  26. </a-col>
  27. <a-col>
  28. <slot name="buttonAfter" :target="getVM()" />
  29. </a-col>
  30. </a-row>
  31. <slot name="actionButtonAfter" :target="getVM()" />
  32. <div :id="`${caseId}inputTable`" class="input-table" :style="{ 'min-width': minWidth + 'px' }">
  33. <!-- 渲染表头 -->
  34. <div class="thead" ref="thead">
  35. <div class="tr" :style="{ width: this.realTrWidth }">
  36. <!-- 左侧固定td -->
  37. <div v-if="dragSort" class="td td-ds" :style="style.tdLeftDs">
  38. <span></span>
  39. </div>
  40. <div v-if="dragSortAndNumber" class="td td-ds" :style="style.tdLeftDs">
  41. <span>#</span>
  42. </div>
  43. <div v-if="rowNumber" class="td td-num" :style="style.tdLeft">
  44. <span>#</span>
  45. </div>
  46. <div v-if="rowSelection" class="td td-cb" :style="style.tdLeft">
  47. <!--:indeterminate="true"-->
  48. <a-checkbox
  49. :checked="getSelectAll"
  50. :indeterminate="getSelectIndeterminate"
  51. @change="handleChangeCheckedAll"
  52. />
  53. </div>
  54. <!-- 右侧动态生成td -->
  55. <template v-for="col in columns">
  56. <div v-show="col.type !== formTypes.hidden" class="td" :key="col.key" :style="buildTdStyle(col)">
  57. <span style="padding: 0 5px">
  58. {{ col.title }}
  59. <slot name="depotBatchSet" v-if="col.key === 'depotId'" :target="getVM()" />
  60. </span>
  61. </div>
  62. </template>
  63. </div>
  64. </div>
  65. <div class="scroll-view" ref="scrollView" :style="{ 'max-height': maxHeight + 'px' }">
  66. <!-- 渲染主体 body -->
  67. <div :id="`${caseId}tbody`" class="tbody" :style="tbodyStyle">
  68. <!-- 扩展高度 -->
  69. <div class="tr-expand" :style="`height:${getExpandHeight}px; z-index:${loading ? '11' : '9'};`"></div>
  70. <!-- 无数据时显示 -->
  71. <div v-if="rows.length === 0" class="tr-nodata">
  72. <span>暂无数据</span>
  73. </div>
  74. <!-- v-model="rows"-->
  75. <draggable :value="rows" handle=".td-ds-icons" @start="handleDragMoveStart" @end="handleDragMoveEnd">
  76. <!-- 动态生成tr -->
  77. <template v-for="(row, rowIndex) in rows">
  78. <!-- tr 如果超出200条,则只加载可见的和预加载的总共十条数据 -->
  79. <div
  80. v-if="
  81. rows.length <= 200 ||
  82. (rows.length > 200 &&
  83. rowIndex >= parseInt(`${(scrollTop - rowHeight) / rowHeight}`) &&
  84. parseInt(`${scrollTop / rowHeight}`) + 9 > rowIndex)
  85. "
  86. :id="`${caseId}tbody-tr-${rowIndex}`"
  87. :data-idx="rowIndex"
  88. class="tr"
  89. :class="selectedRowIds.indexOf(row.id) !== -1 ? 'tr-checked' : ''"
  90. :style="buildTrStyle(rowIndex)"
  91. :key="row.id"
  92. >
  93. <!-- 左侧固定td -->
  94. <div v-if="dragSort" class="td td-ds" :style="style.tdLeftDs">
  95. <a-dropdown :trigger="['click']" :getPopupContainer="getParentContainer">
  96. <div class="td-ds-icons">
  97. <a-icon type="align-left" />
  98. <a-icon type="align-right" />
  99. </div>
  100. <a-menu slot="overlay">
  101. <a-menu-item key="0" :disabled="rowIndex === 0" @click="_handleRowMoveUp(rowIndex)"
  102. >向上移</a-menu-item
  103. >
  104. <a-menu-item
  105. key="1"
  106. :disabled="rowIndex === rows.length - 1"
  107. @click="_handleRowMoveDown(rowIndex)"
  108. >向下移</a-menu-item
  109. >
  110. <!-- <a-menu-divider/>
  111. <a-menu-item key="3" @click="_handleRowInsertDown(rowIndex)">插入一行</a-menu-item> -->
  112. </a-menu>
  113. </a-dropdown>
  114. </div>
  115. <div v-if="dragSortAndNumber" class="td td-ds" :style="style.tdLeftDs">
  116. <a-dropdown :trigger="['click']" :getPopupContainer="getParentContainer">
  117. <div class="td-ds-icons" title="点击不放可以拖动" style="text-align: center; line-height: 32px">
  118. <span>{{ rowIndex + 1 }}</span>
  119. </div>
  120. <a-menu slot="overlay">
  121. <a-menu-item key="0" :disabled="rowIndex === 0" @click="_handleRowMoveUp(rowIndex)"
  122. >向上移</a-menu-item
  123. >
  124. <a-menu-item
  125. key="1"
  126. :disabled="rowIndex === rows.length - 1"
  127. @click="_handleRowMoveDown(rowIndex)"
  128. >向下移</a-menu-item
  129. >
  130. <!-- <a-menu-divider/>
  131. <a-menu-item key="3" @click="_handleRowInsertDown(rowIndex)">插入一行</a-menu-item> -->
  132. </a-menu>
  133. </a-dropdown>
  134. </div>
  135. <div v-if="rowNumber" class="td td-num" :style="style.tdLeft">
  136. <span>{{ rowIndex + 1 }}</span>
  137. </div>
  138. <div v-if="rowSelection" class="td td-cb" :style="style.tdLeft">
  139. <!-- 此 v-for 只是为了拼接 id 字符串 -->
  140. <template v-for="(id, i) in [`${row.id}`]">
  141. <a-checkbox
  142. :id="id"
  143. :key="i"
  144. :checked="selectedRowIds.indexOf(id) !== -1"
  145. @change="handleChangeLeftCheckbox"
  146. />
  147. </template>
  148. </div>
  149. <!-- 右侧动态生成td -->
  150. <div
  151. class="td"
  152. v-for="col in columns"
  153. v-show="col.type !== formTypes.hidden"
  154. :key="col.key"
  155. :style="buildTdStyle(col)"
  156. >
  157. <!-- 此 v-for 只是为了拼接 id 字符串 -->
  158. <template v-for="(id, i) in [`${col.key}${row.id}`]">
  159. <!-- native input -->
  160. <label :key="i" v-if="col.type === formTypes.input || col.type === formTypes.inputNumber">
  161. <a-tooltip
  162. :id="id"
  163. placement="top"
  164. :title="(tooltips[id] || {}).title"
  165. :visible="(tooltips[id] || {}).visible || false"
  166. :autoAdjustOverflow="true"
  167. :getPopupContainer="getParentContainer"
  168. >
  169. <input
  170. :id="id"
  171. :readonly="col.readonly"
  172. :visible="col.visible"
  173. v-bind="buildProps(row, col)"
  174. :data-input-number="col.type === formTypes.inputNumber"
  175. :placeholder="replaceProps(col, col.placeholder)"
  176. @blur="
  177. (e) => {
  178. handleBlurCommono(e.target, rowIndex, row, col)
  179. }
  180. "
  181. @input="
  182. (e) => {
  183. handleInputCommono(e.target, rowIndex, row, col)
  184. }
  185. "
  186. @mouseover="
  187. () => {
  188. handleMouseoverCommono(row, col)
  189. }
  190. "
  191. @mouseout="
  192. () => {
  193. handleMouseoutCommono(row, col)
  194. }
  195. "
  196. />
  197. </a-tooltip>
  198. </label>
  199. <!-- checkbox -->
  200. <template v-else-if="col.type === formTypes.checkbox">
  201. <a-checkbox
  202. :key="i"
  203. :id="id"
  204. v-bind="buildProps(row, col)"
  205. :checked="checkboxValues[id]"
  206. @change="(e) => handleChangeCheckboxCommon(e, row, col)"
  207. />
  208. </template>
  209. <!-- select -->
  210. <template v-else-if="col.type === formTypes.select">
  211. <a-tooltip
  212. :key="i"
  213. :id="id"
  214. placement="top"
  215. :title="(tooltips[id] || {}).title"
  216. :visible="(tooltips[id] || {}).visible || false"
  217. :autoAdjustOverflow="true"
  218. :getPopupContainer="getParentContainer"
  219. >
  220. <span
  221. @mouseover="
  222. () => {
  223. handleMouseoverCommono(row, col)
  224. }
  225. "
  226. @mouseout="
  227. () => {
  228. handleMouseoutCommono(row, col)
  229. }
  230. "
  231. >
  232. <a-select
  233. :id="id"
  234. :key="i"
  235. v-bind="buildProps(row, col)"
  236. style="width: 100%"
  237. :value="getSelectValue(id)"
  238. :options="col.options"
  239. :getPopupContainer="getParentContainer"
  240. :placeholder="replaceProps(col, col.placeholder)"
  241. :filterOption="(i, o) => handleSelectFilterOption(i, o, col)"
  242. @change="(v) => handleChangeSelectCommon(v, id, row, col)"
  243. @search="(v) => handleSearchSelect(v, id, row, col)"
  244. @blur="(v) => handleBlurSearch(v, id, row, col)"
  245. @focus="(v) => handleFocusSearch(v, id, row, col)"
  246. >
  247. <div slot="dropdownRender" slot-scope="menu">
  248. <v-nodes :vnodes="menu" />
  249. <slot name="depotAdd" v-if="col.key === 'depotId'" :target="getVM()" />
  250. <slot name="inOutItemAdd" v-if="col.key === 'inOutItemId'" :target="getVM()" />
  251. </div>
  252. <!-- <template v-for="(opt, optKey) in col.options">
  253. <a-select-option :value="opt.value" :key="optKey">{{ opt.title }}</a-select-option>
  254. </template> -->
  255. </a-select>
  256. </span>
  257. </a-tooltip>
  258. </template>
  259. <!-- date -->
  260. <template v-else-if="col.type === formTypes.date || col.type === formTypes.datetime">
  261. <a-tooltip
  262. :key="i"
  263. :id="id"
  264. placement="top"
  265. :title="(tooltips[id] || {}).title"
  266. :visible="(tooltips[id] || {}).visible || false"
  267. :autoAdjustOverflow="true"
  268. :getPopupContainer="getParentContainer"
  269. >
  270. <span
  271. @mouseover="
  272. () => {
  273. handleMouseoverCommono(row, col)
  274. }
  275. "
  276. @mouseout="
  277. () => {
  278. handleMouseoutCommono(row, col)
  279. }
  280. "
  281. >
  282. <j-date
  283. :id="id"
  284. :key="i"
  285. v-bind="buildProps(row, col)"
  286. style="width: 100%"
  287. :value="jdateValues[id]"
  288. :getCalendarContainer="getParentContainer"
  289. :placeholder="replaceProps(col, col.placeholder)"
  290. :trigger-change="true"
  291. :showTime="col.type === formTypes.datetime"
  292. :dateFormat="col.type === formTypes.date ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
  293. allowClear
  294. @change="(v) => handleChangeJDateCommon(v, id, row, col, col.type === formTypes.datetime)"
  295. />
  296. </span>
  297. </a-tooltip>
  298. </template>
  299. <!-- input_pop -->
  300. <template v-else-if="col.type === formTypes.input_pop">
  301. <a-tooltip
  302. :key="i"
  303. :id="id"
  304. placement="top"
  305. :title="(tooltips[id] || {}).title"
  306. :visible="(tooltips[id] || {}).visible || false"
  307. :autoAdjustOverflow="true"
  308. :getPopupContainer="getParentContainer"
  309. >
  310. <span
  311. @mouseover="
  312. () => {
  313. handleMouseoverCommono(row, col)
  314. }
  315. "
  316. @mouseout="
  317. () => {
  318. handleMouseoutCommono(row, col)
  319. }
  320. "
  321. >
  322. <j-input-pop
  323. :id="id"
  324. :key="i"
  325. :width="300"
  326. :height="210"
  327. :pop-container="`${caseId}tbody`"
  328. v-bind="buildProps(row, col)"
  329. style="width: 100%"
  330. :value="jInputPopValues[id]"
  331. :getCalendarContainer="getParentContainer"
  332. :placeholder="replaceProps(col, col.placeholder)"
  333. @change="(v) => handleChangeJInputPopCommon(v, id, row, col)"
  334. >
  335. </j-input-pop>
  336. </span>
  337. </a-tooltip>
  338. </template>
  339. <div v-else-if="col.type === formTypes.upload" :key="i + 1">
  340. <template v-if="uploadValues[id] != null">
  341. <a-input
  342. v-for="(file, fileKey) of [uploadValues[id] || {}]"
  343. :key="fileKey"
  344. :readOnly="true"
  345. :value="file.name"
  346. >
  347. <template slot="addonBefore">
  348. <div style="width: 30px">
  349. <a-tooltip
  350. v-if="file.status === 'uploading'"
  351. :title="`上传中(${Math.floor(file.percent)}%)`"
  352. >
  353. <a-icon type="loading" />
  354. </a-tooltip>
  355. <a-tooltip v-else-if="file.status === 'done'" title="上传完成">
  356. <a-icon type="check-circle" style="color: #00db00" />
  357. </a-tooltip>
  358. <a-tooltip v-else title="上传失败">
  359. <a-icon type="exclamation-circle" style="color: red" />
  360. </a-tooltip>
  361. </div>
  362. </template>
  363. <template v-if="col.allowDownload !== false || col.allowRemove !== false" slot="addonAfter">
  364. <div style="width: 30px">
  365. <a-dropdown
  366. :trigger="['click']"
  367. placement="bottomRight"
  368. :getPopupContainer="getParentContainer"
  369. >
  370. <a-tooltip title="操作" :getPopupContainer="getParentContainer">
  371. <a-icon v-if="file.status !== 'uploading'" type="setting" style="cursor: pointer" />
  372. </a-tooltip>
  373. <a-menu slot="overlay">
  374. <a-menu-item v-if="col.allowDownload !== false" @click="handleClickDownloadFile(id)">
  375. <span><a-icon type="download" />&nbsp;下载</span>
  376. </a-menu-item>
  377. <a-menu-item v-if="col.allowRemove !== false" @click="handleClickDelFile(id)">
  378. <span><a-icon type="delete" />&nbsp;删除</span>
  379. </a-menu-item>
  380. </a-menu>
  381. </a-dropdown>
  382. </div>
  383. </template>
  384. </a-input>
  385. </template>
  386. <div :hidden="uploadValues[id] != null">
  387. <a-tooltip
  388. :key="i"
  389. :id="id"
  390. placement="top"
  391. :title="(tooltips[id] || {}).title"
  392. :visible="(tooltips[id] || {}).visible || false"
  393. :autoAdjustOverflow="true"
  394. :getPopupContainer="getParentContainer"
  395. >
  396. <span
  397. @mouseover="
  398. () => {
  399. handleMouseoverCommono(row, col)
  400. }
  401. "
  402. @mouseout="
  403. () => {
  404. handleMouseoutCommono(row, col)
  405. }
  406. "
  407. >
  408. <a-upload
  409. name="file"
  410. :data="{ isup: 1 }"
  411. :multiple="false"
  412. :action="col.action"
  413. :headers="uploadGetHeaders(row, col)"
  414. :showUploadList="false"
  415. v-bind="buildProps(row, col)"
  416. @change="(v) => handleChangeUpload(v, id, row, col)"
  417. >
  418. <a-button icon="upload">{{ col.placeholder }}</a-button>
  419. </a-upload>
  420. </span>
  421. </a-tooltip>
  422. </div>
  423. </div>
  424. <!-- update-begin-author:taoyan date:0827 for:popup -->
  425. <template v-else-if="col.type === formTypes.popup">
  426. <a-tooltip
  427. :key="i"
  428. :id="id"
  429. placement="top"
  430. :title="(tooltips[id] || {}).title"
  431. :visible="(tooltips[id] || {}).visible || false"
  432. :autoAdjustOverflow="true"
  433. :getPopupContainer="getParentContainer"
  434. >
  435. <span
  436. @mouseover="
  437. () => {
  438. handleMouseoverCommono(row, col)
  439. }
  440. "
  441. @mouseout="
  442. () => {
  443. handleMouseoutCommono(row, col)
  444. }
  445. "
  446. >
  447. <j-popup
  448. :id="id"
  449. :key="i"
  450. v-bind="buildProps(row, col)"
  451. :placeholder="replaceProps(col, col.placeholder)"
  452. style="width: 100%"
  453. :value="getPopupValue(id)"
  454. :field="col.field || col.key"
  455. :org-fields="col.orgFields"
  456. :dest-fields="col.destFields"
  457. :code="col.popupCode"
  458. :groupId="caseId"
  459. @input="(value, others) => popupCallback(value, others, id, row, col, rowIndex)"
  460. />
  461. </span>
  462. </a-tooltip>
  463. </template>
  464. <!-- update-end-author:taoyan date:0827 for:popup -->
  465. <!-- update-begin-author:jsh date:20210308 for:popupJsh -->
  466. <template v-else-if="col.type === formTypes.popupJsh">
  467. <div style="max-width: 200px" :key="i">
  468. <a-tooltip
  469. :id="id"
  470. placement="top"
  471. :title="(tooltips[id] || {}).title"
  472. :visible="(tooltips[id] || {}).visible || false"
  473. :autoAdjustOverflow="true"
  474. :getPopupContainer="getParentContainer"
  475. >
  476. <span
  477. @mouseover="
  478. () => {
  479. handleMouseoverCommono(row, col)
  480. }
  481. "
  482. @mouseout="
  483. () => {
  484. handleMouseoutCommono(row, col)
  485. }
  486. "
  487. >
  488. <j-select-list
  489. :rows="getPopupJshRows(row)"
  490. :kind="col.kind"
  491. :multi="col.multi"
  492. :value="getPopupJshValue(id)"
  493. @change="(v) => handleChangePopupJshCommon(v, id, row, col, rowIndex)"
  494. />
  495. </span>
  496. </a-tooltip>
  497. </div>
  498. </template>
  499. <!-- update-end-author:jsh date:20210308 for:popupJsh -->
  500. <!-- update-beign-author:taoyan date:0827 for:文件/图片逻辑新增 -->
  501. <div v-else-if="col.type === formTypes.file" :key="i + 2">
  502. <template v-if="uploadValues[id] != null">
  503. <div
  504. v-for="(file, fileKey) of [uploadValues[id] || {}]"
  505. :key="fileKey"
  506. style="position: relative"
  507. >
  508. <a-tooltip v-if="file.status === 'uploading'" :title="`上传中(${Math.floor(file.percent)}%)`">
  509. <a-icon type="loading" style="color: red" />
  510. <span style="color: red; margin-left: 5px">{{ file.status }}</span>
  511. </a-tooltip>
  512. <a-tooltip v-else-if="file.status === 'done'" :title="file.name">
  513. <a-icon type="paper-clip" />
  514. <span style="margin-left: 5px">{{ getEllipsisWord(file.name, 5) }}</span>
  515. </a-tooltip>
  516. <a-tooltip v-else :title="file.name">
  517. <a-icon type="paper-clip" style="color: red" />
  518. <span style="color: red; margin-left: 5px">{{ getEllipsisWord(file.name, 5) }}</span>
  519. </a-tooltip>
  520. <template style="width: 30px">
  521. <a-dropdown
  522. :trigger="['click']"
  523. placement="bottomRight"
  524. :getPopupContainer="getParentContainer"
  525. style="margin-left: 10px"
  526. >
  527. <a-tooltip title="操作" :getPopupContainer="getParentContainer">
  528. <a-icon v-if="file.status !== 'uploading'" type="setting" style="cursor: pointer" />
  529. </a-tooltip>
  530. <a-menu slot="overlay">
  531. <a-menu-item v-if="col.allowDownload !== false" @click="handleClickDownFileByUrl(id)">
  532. <span><a-icon type="download" />&nbsp;下载</span>
  533. </a-menu-item>
  534. <a-menu-item @click="handleClickDelFile(id)">
  535. <span><a-icon type="delete" />&nbsp;删除</span>
  536. </a-menu-item>
  537. <a-menu-item @click="handleMoreOperation(id)">
  538. <span><a-icon type="bars" /> 更多</span>
  539. </a-menu-item>
  540. </a-menu>
  541. </a-dropdown>
  542. </template>
  543. </div>
  544. </template>
  545. <div :hidden="uploadValues[id] != null">
  546. <a-tooltip
  547. :key="i"
  548. :id="id"
  549. placement="top"
  550. :title="(tooltips[id] || {}).title"
  551. :visible="(tooltips[id] || {}).visible || false"
  552. :autoAdjustOverflow="true"
  553. :getPopupContainer="getParentContainer"
  554. >
  555. <span
  556. @mouseover="
  557. () => {
  558. handleMouseoverCommono(row, col)
  559. }
  560. "
  561. @mouseout="
  562. () => {
  563. handleMouseoutCommono(row, col)
  564. }
  565. "
  566. >
  567. <a-upload
  568. name="file"
  569. :data="{ isup: 1 }"
  570. :multiple="false"
  571. :action="getUploadAction(col.action)"
  572. :headers="uploadGetHeaders(row, col)"
  573. :showUploadList="false"
  574. v-bind="buildProps(row, col)"
  575. @change="(v) => handleChangeUpload(v, id, row, col)"
  576. >
  577. <a-button icon="upload">上传文件</a-button>
  578. </a-upload>
  579. </span>
  580. </a-tooltip>
  581. </div>
  582. </div>
  583. <div v-else-if="col.type === formTypes.image" :key="i + 3">
  584. <template v-if="uploadValues[id] != null">
  585. <div
  586. v-for="(file, fileKey) of [uploadValues[id] || {}]"
  587. :key="fileKey"
  588. style="position: relative"
  589. >
  590. <template
  591. v-if="
  592. !uploadValues[id] ||
  593. !(uploadValues[id]['url'] || uploadValues[id]['path'] || uploadValues[id]['message'])
  594. "
  595. >
  596. <a-icon type="loading" />
  597. </template>
  598. <template v-else-if="uploadValues[id]['path']">
  599. <img
  600. class="j-editable-image"
  601. :src="getCellImageView(id)"
  602. alt="无图片"
  603. @click="handleMoreOperation(id, 'img')"
  604. />
  605. </template>
  606. <template v-else>
  607. <a-icon
  608. type="exclamation-circle"
  609. style="color: red"
  610. @click="handleClickShowImageError(id)"
  611. />
  612. </template>
  613. <template slot="addonBefore">
  614. <div style="width: 30px">
  615. <a-tooltip
  616. v-if="file.status === 'uploading'"
  617. :title="`上传中(${Math.floor(file.percent)}%)`"
  618. >
  619. <a-icon type="loading" />
  620. </a-tooltip>
  621. <a-tooltip v-else-if="file.status === 'done'" title="上传完成">
  622. <a-icon type="check-circle" style="color: #00db00" />
  623. </a-tooltip>
  624. <a-tooltip v-else title="上传失败">
  625. <a-icon type="exclamation-circle" style="color: red" />
  626. </a-tooltip>
  627. </div>
  628. </template>
  629. <template style="width: 30px">
  630. <a-dropdown
  631. :trigger="['click']"
  632. placement="bottomRight"
  633. :getPopupContainer="getParentContainer"
  634. style="margin-left: 10px"
  635. >
  636. <a-tooltip title="操作" :getPopupContainer="getParentContainer">
  637. <a-icon v-if="file.status !== 'uploading'" type="setting" style="cursor: pointer" />
  638. </a-tooltip>
  639. <a-menu slot="overlay">
  640. <a-menu-item v-if="col.allowDownload !== false" @click="handleClickDownFileByUrl(id)">
  641. <span><a-icon type="download" />&nbsp;下载</span>
  642. </a-menu-item>
  643. <a-menu-item @click="handleClickDelFile(id)">
  644. <span><a-icon type="delete" />&nbsp;删除</span>
  645. </a-menu-item>
  646. <a-menu-item @click="handleMoreOperation(id, 'img')">
  647. <span><a-icon type="bars" /> 更多</span>
  648. </a-menu-item>
  649. </a-menu>
  650. </a-dropdown>
  651. </template>
  652. </div>
  653. </template>
  654. <div :hidden="uploadValues[id] != null">
  655. <a-tooltip
  656. :key="i"
  657. :id="id"
  658. placement="top"
  659. :title="(tooltips[id] || {}).title"
  660. :visible="(tooltips[id] || {}).visible || false"
  661. :autoAdjustOverflow="true"
  662. :getPopupContainer="getParentContainer"
  663. >
  664. <span
  665. @mouseover="
  666. () => {
  667. handleMouseoverCommono(row, col)
  668. }
  669. "
  670. @mouseout="
  671. () => {
  672. handleMouseoutCommono(row, col)
  673. }
  674. "
  675. >
  676. <a-upload
  677. name="file"
  678. :data="{ isup: 1 }"
  679. :multiple="false"
  680. :action="getUploadAction(col.action)"
  681. :headers="uploadGetHeaders(row, col)"
  682. :showUploadList="false"
  683. v-bind="buildProps(row, col)"
  684. @change="(v) => handleChangeUpload(v, id, row, col)"
  685. >
  686. <a-button icon="upload">上传图片</a-button>
  687. </a-upload>
  688. </span>
  689. </a-tooltip>
  690. </div>
  691. </div>
  692. <!-- update-end-author:taoyan date:0827 for:图片逻辑新增 -->
  693. <!-- radio-begin -->
  694. <template v-else-if="col.type === formTypes.radio">
  695. <a-tooltip
  696. :key="i"
  697. :id="id"
  698. placement="top"
  699. :title="(tooltips[id] || {}).title"
  700. :visible="(tooltips[id] || {}).visible || false"
  701. :autoAdjustOverflow="true"
  702. :getPopupContainer="getParentContainer"
  703. >
  704. <span
  705. @mouseover="
  706. () => {
  707. handleMouseoverCommono(row, col)
  708. }
  709. "
  710. @mouseout="
  711. () => {
  712. handleMouseoutCommono(row, col)
  713. }
  714. "
  715. >
  716. <a-radio-group
  717. :id="id"
  718. :key="i"
  719. v-bind="buildProps(row, col)"
  720. :value="radioValues[id]"
  721. @change="(e) => handleRadioChange(e.target.value, id, row, col)"
  722. >
  723. <a-radio v-for="(item, key) in col.options" :key="key" :value="item.value">{{
  724. item.text
  725. }}</a-radio>
  726. </a-radio-group>
  727. </span>
  728. </a-tooltip>
  729. </template>
  730. <!-- radio-end -->
  731. <!-- select多选 -begin -->
  732. <template v-else-if="col.type === formTypes.list_multi">
  733. <a-tooltip
  734. :key="i"
  735. :id="id"
  736. placement="top"
  737. :title="(tooltips[id] || {}).title"
  738. :visible="(tooltips[id] || {}).visible || false"
  739. :autoAdjustOverflow="true"
  740. :getPopupContainer="getParentContainer"
  741. >
  742. <span
  743. @mouseover="
  744. () => {
  745. handleMouseoverCommono(row, col)
  746. }
  747. "
  748. @mouseout="
  749. () => {
  750. handleMouseoutCommono(row, col)
  751. }
  752. "
  753. >
  754. <a-select
  755. :id="id"
  756. :key="i"
  757. mode="multiple"
  758. :maxTagCount="1"
  759. v-bind="buildProps(row, col)"
  760. style="width: 100%"
  761. :value="multiSelectValues[id]"
  762. :options="col.options"
  763. :getPopupContainer="getParentContainer"
  764. :placeholder="replaceProps(col, col.placeholder)"
  765. @change="(v) => handleMultiSelectChange(v, id, row, col)"
  766. allowClear
  767. >
  768. </a-select>
  769. </span>
  770. </a-tooltip>
  771. </template>
  772. <!-- select多选 -end -->
  773. <!-- select搜索 -begin -->
  774. <template v-else-if="col.type === formTypes.sel_search">
  775. <a-tooltip
  776. :key="i"
  777. :id="id"
  778. placement="top"
  779. :title="(tooltips[id] || {}).title"
  780. :visible="(tooltips[id] || {}).visible || false"
  781. :autoAdjustOverflow="true"
  782. :getPopupContainer="getParentContainer"
  783. >
  784. <span
  785. @mouseover="
  786. () => {
  787. handleMouseoverCommono(row, col)
  788. }
  789. "
  790. @mouseout="
  791. () => {
  792. handleMouseoutCommono(row, col)
  793. }
  794. "
  795. >
  796. <a-select
  797. :id="id"
  798. :key="i"
  799. showSearch
  800. optionFilterProp="children"
  801. :filterOption="filterOption"
  802. v-bind="buildProps(row, col)"
  803. style="width: 100%"
  804. :value="searchSelectValues[id]"
  805. :options="col.options"
  806. :getPopupContainer="getParentContainer"
  807. :placeholder="replaceProps(col, col.placeholder)"
  808. @change="(v) => handleSearchSelectChange(v, id, row, col)"
  809. allowClear
  810. >
  811. </a-select>
  812. </span>
  813. </a-tooltip>
  814. </template>
  815. <!-- select搜索 -end -->
  816. <div v-else-if="col.type === formTypes.slot" :key="i + 4">
  817. <a-tooltip
  818. :key="i"
  819. :id="id"
  820. placement="top"
  821. :title="(tooltips[id] || {}).title"
  822. :visible="(tooltips[id] || {}).visible || false"
  823. :autoAdjustOverflow="true"
  824. :getPopupContainer="getParentContainer"
  825. >
  826. <span
  827. @mouseover="
  828. () => {
  829. handleMouseoverCommono(row, col)
  830. }
  831. "
  832. @mouseout="
  833. () => {
  834. handleMouseoutCommono(row, col)
  835. }
  836. "
  837. >
  838. <slot
  839. :name="col.slot || col.slotName || col.key"
  840. :index="rowIndex"
  841. :text="slotValues[id]"
  842. :value="slotValues[id]"
  843. :column="col"
  844. :rowId="getCleanId(row.id)"
  845. :getValue="() => _getValueForSlot(row.id)"
  846. :caseId="caseId"
  847. :allValues="_getAllValuesForSlot()"
  848. :target="getVM()"
  849. :handleChange="(v) => handleChangeSlotCommon(v, id, row, col)"
  850. :handleFocus="(v) => handleFocusSlotCommon(v, id, row, col)"
  851. :isNotPass="notPassedIds.includes(col.key + row.id)"
  852. />
  853. </span>
  854. </a-tooltip>
  855. </div>
  856. <!-- else (normal) -->
  857. <span
  858. v-else
  859. :key="i + 5"
  860. v-bind="buildProps(row, col)"
  861. class="td-span"
  862. :title="inputValues[rowIndex][col.key]"
  863. >
  864. {{ inputValues[rowIndex][col.key] }}
  865. </span>
  866. </template>
  867. </div>
  868. </div>
  869. <!-- -- tr end -- -->
  870. </template>
  871. </draggable>
  872. <!-- 统计行 -->
  873. <div
  874. v-if="showStatisticsRow"
  875. class="tr"
  876. :style="{
  877. ...buildTrStyle(rows.length),
  878. height: '32px',
  879. }"
  880. >
  881. <div v-if="dragSort" class="td td-ds" :style="style.tdLeftDs"></div>
  882. <div v-if="dragSortAndNumber" class="td td-ds" :style="style.tdLeftDs"></div>
  883. <div v-if="rowNumber" class="td td-num" :style="style.tdLeft">
  884. <span v-if="!rowSelection">统计</span>
  885. </div>
  886. <div v-if="rowSelection" class="td td-cb" :style="style.tdLeft"></div>
  887. <!-- 右侧动态生成td -->
  888. <template v-for="col in columns">
  889. <div :key="col.key" class="td" v-show="col.type !== formTypes.hidden" :style="buildTdStyle(col)">
  890. <span v-show="col.type === formTypes.inputNumber" style="padding: 0 2px">{{
  891. statisticsColumns[col.key]
  892. }}</span>
  893. </div>
  894. </template>
  895. </div>
  896. </div>
  897. </div>
  898. <j-file-pop ref="filePop" @ok="handleFileSuccess"></j-file-pop>
  899. </div>
  900. </a-spin>
  901. </template>
  902. <script>
  903. import Vue from 'vue'
  904. import $ from 'jquery'
  905. import Draggable from 'vuedraggable'
  906. import { ACCESS_TOKEN } from '@/store/mutation-types'
  907. import { FormTypes, VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
  908. import { cloneObject, randomString, randomNumber } from '@/utils/util'
  909. import JDate from '@/components/jeecg/JDate'
  910. import { getFileAccessHttpUrl } from '@/api/manage'
  911. import JInputPop from '@/components/jeecg/minipop/JInputPop'
  912. import JFilePop from '@/components/jeecg/minipop/JFilePop'
  913. import JSelectList from '@/components/jeecgbiz/JSelectList'
  914. // import { BillModalMixin } from '../../../src/views/bill/mixins/BillModalMixin'
  915. // 行高,需要在实例加载完成前用到
  916. let rowHeight = 42
  917. export default {
  918. // mixins: [BillModalMixin],
  919. name: 'JEditableTable',
  920. components: {
  921. JDate,
  922. Draggable,
  923. JInputPop,
  924. JFilePop,
  925. JSelectList,
  926. VNodes: {
  927. functional: true,
  928. render: (h, ctx) => ctx.props.vnodes,
  929. },
  930. },
  931. provide() {
  932. return {
  933. parentIsJEditableTable: true,
  934. getDestroyCleanGroupRequest: () => this.destroyCleanGroupRequest,
  935. }
  936. },
  937. props: {
  938. // 列信息
  939. columns: {
  940. type: Array,
  941. required: true,
  942. },
  943. // 数据源
  944. dataSource: {
  945. type: Array,
  946. required: true,
  947. default: () => [],
  948. },
  949. // 是否显示操作按钮
  950. actionButton: {
  951. type: Boolean,
  952. default: false,
  953. },
  954. // 是否显示行号
  955. rowNumber: {
  956. type: Boolean,
  957. default: false,
  958. },
  959. // 是否可选择行
  960. rowSelection: {
  961. type: Boolean,
  962. default: false,
  963. },
  964. // 页面是否在加载中
  965. loading: {
  966. type: Boolean,
  967. default: false,
  968. },
  969. // 页面是否在加载中
  970. minWidth: {
  971. type: Number,
  972. default: 1500,
  973. },
  974. maxHeight: {
  975. type: Number,
  976. default: 400,
  977. },
  978. // 要禁用的行
  979. disabledRows: {
  980. type: Object,
  981. default() {
  982. return {}
  983. },
  984. },
  985. // 是否禁用全部组件
  986. disabled: {
  987. type: Boolean,
  988. default: false,
  989. },
  990. // 是否可拖拽排序
  991. dragSort: {
  992. type: Boolean,
  993. default: false,
  994. },
  995. // 是否可拖拽排序并显示行号
  996. dragSortAndNumber: {
  997. type: Boolean,
  998. default: false,
  999. },
  1000. dragSortKey: {
  1001. type: String,
  1002. default: 'orderNum',
  1003. },
  1004. },
  1005. data() {
  1006. return {
  1007. // 是否首次运行
  1008. isFirst: true,
  1009. // 当前实例是否是行编辑
  1010. isJEditableTable: true,
  1011. // caseId,用于防止有多个实例的时候会冲突
  1012. caseIdPrefix: '_jet-',
  1013. caseId: `_jet-${randomString(6)}-`,
  1014. // 临时ID标识,凡是以该标识结尾的ID都是临时ID,不添加到数据库中
  1015. tempId: `_tid-${randomString(6)}`,
  1016. // 存储document element 对象
  1017. el: {
  1018. inputTable: null,
  1019. tbody: null,
  1020. },
  1021. // 存储各个div的style
  1022. style: {
  1023. // 'max-height': '400px'
  1024. tbody: { left: '0px' },
  1025. // 左侧固定td的style
  1026. // 20200331 cfm modify
  1027. // tdLeft: { 'min-width': '4%', 'max-width': '45px' },
  1028. tdLeft: { 'min-width': '40px', 'max-width': '45px' },
  1029. tdLeftDs: { 'min-width': '30px', 'max-width': '35px' },
  1030. },
  1031. // 表单的类型
  1032. formTypes: FormTypes,
  1033. // 行数据
  1034. rows: [],
  1035. // 行高,height + padding + border
  1036. rowHeight,
  1037. // 滚动条顶部距离
  1038. scrollTop: 0,
  1039. // 绑定 select 的值
  1040. selectValues: {},
  1041. // 绑定 checkbox 的值
  1042. checkboxValues: {},
  1043. // 绑定 jdate 的值
  1044. jdateValues: {},
  1045. // 绑定jinputpop
  1046. jInputPopValues: {},
  1047. // 绑定插槽数据
  1048. slotValues: {},
  1049. // file 信息
  1050. uploadValues: {},
  1051. //popup信息
  1052. popupValues: {},
  1053. //popupJsh信息
  1054. popupJshValues: {},
  1055. radioValues: {},
  1056. metaCheckboxValues: {},
  1057. multiSelectValues: {},
  1058. searchSelectValues: {},
  1059. // 绑定左侧选择框已选择的id
  1060. selectedRowIds: [],
  1061. // 存储被删除行的id
  1062. deleteIds: [],
  1063. // 存储显示tooltip的信息
  1064. tooltips: {},
  1065. // 存储没有通过验证的inputId
  1066. notPassedIds: [],
  1067. // 当前是否正在拖拽排序
  1068. dragging: false,
  1069. // 是否有统计列
  1070. hasStatisticsColumn: false,
  1071. statisticsColumns: {},
  1072. // 只有在行编辑被销毁时才主动清空GroupRequest的内存
  1073. destroyCleanGroupRequest: false,
  1074. }
  1075. },
  1076. created() {
  1077. this.inputValues = []
  1078. // 当前显示的tr
  1079. this.visibleTrEls = []
  1080. this.disabledRowIds = this.disabledRowIds || []
  1081. },
  1082. // 计算属性
  1083. computed: {
  1084. // expandHeight = rows.length * rowHeight
  1085. getExpandHeight() {
  1086. let length = this.rows.length * this.rowHeight
  1087. if (this.showStatisticsRow) {
  1088. length += 34
  1089. }
  1090. return length
  1091. },
  1092. // 是否显示统计行
  1093. showStatisticsRow() {
  1094. return this.hasStatisticsColumn && this.rows.length > 0
  1095. },
  1096. // 获取是否选择了部分
  1097. getSelectIndeterminate() {
  1098. return this.selectedRowIds.length > 0 && this.selectedRowIds.length < this.rows.length
  1099. },
  1100. // 获取是否选择了全部
  1101. getSelectAll() {
  1102. return this.selectedRowIds.length === this.rows.length && this.rows.length > 0
  1103. },
  1104. tbodyStyle() {
  1105. let style = Object.assign({}, this.style.tbody)
  1106. // style['max-height'] = `${this.maxHeight}px`
  1107. style['width'] = this.realTrWidth
  1108. return style
  1109. },
  1110. showClearSelectButton() {
  1111. let count = 0
  1112. for (let key in this.disabledRows) {
  1113. if (this.disabledRows.hasOwnProperty(key)) count++
  1114. }
  1115. return count > 0
  1116. },
  1117. accessToken() {
  1118. return Vue.ls.get(ACCESS_TOKEN)
  1119. },
  1120. realTrWidth() {
  1121. let splice = ' + '
  1122. let calcWidth = 'calc('
  1123. this.columns.forEach((column, i) => {
  1124. let { type, width } = column
  1125. // 隐藏字段不参与计算
  1126. if (type !== FormTypes.hidden) {
  1127. if (typeof width === 'number') {
  1128. calcWidth += width + 'px'
  1129. } else if (typeof width === 'string') {
  1130. calcWidth += width
  1131. } else {
  1132. calcWidth += '120px'
  1133. }
  1134. calcWidth += splice
  1135. }
  1136. })
  1137. if (calcWidth.endsWith(splice)) {
  1138. calcWidth = calcWidth.substring(0, calcWidth.length - splice.length)
  1139. }
  1140. calcWidth += ')'
  1141. // console.log('calcWidth: ', calcWidth)
  1142. return calcWidth
  1143. },
  1144. },
  1145. // 侦听器
  1146. watch: {
  1147. rows: {
  1148. immediate: true,
  1149. handler(val, old) {
  1150. // val.forEach(item => {
  1151. // for (let inputValue of this.inputValues) {
  1152. // if (inputValue.id === item.id) {
  1153. // item['dbFieldName'] = inputValue['dbFieldName']
  1154. // break
  1155. // }
  1156. // }
  1157. // })
  1158. // console.log('watch.rows:', cloneObject({ val, old }))
  1159. },
  1160. },
  1161. dataSource: {
  1162. immediate: true,
  1163. handler: function (newValue) {
  1164. // 兼容IE
  1165. this.getElementPromise('tbody').then(() => {
  1166. this.initialize()
  1167. this._pushByDataSource(newValue)
  1168. })
  1169. },
  1170. },
  1171. columns: {
  1172. immediate: true,
  1173. handler(columns) {
  1174. // 兼容IE
  1175. this.getElementPromise('tbody').then(() => {
  1176. columns.forEach((column) => {
  1177. if (
  1178. column.type === FormTypes.select ||
  1179. column.type === FormTypes.list_multi ||
  1180. column.type === FormTypes.sel_search
  1181. ) {
  1182. // 兼容 旧版本 options
  1183. if (column.options instanceof Array) {
  1184. column.options = column.options.map((item) => {
  1185. if (item) {
  1186. return {
  1187. ...item,
  1188. text: item.text || item.title,
  1189. title: item.text || item.title,
  1190. }
  1191. }
  1192. return {}
  1193. })
  1194. }
  1195. }
  1196. })
  1197. })
  1198. },
  1199. },
  1200. // 当selectRowIds改变时触发事件
  1201. selectedRowIds(newValue) {
  1202. this.$emit(
  1203. 'selectRowChange',
  1204. cloneObject(newValue).map((i) => this.getCleanId(i))
  1205. )
  1206. },
  1207. },
  1208. mounted() {
  1209. let vm = this
  1210. /** 监听滚动条事件 */
  1211. this.getElement('inputTable').onscroll = function (event) {
  1212. vm.syncScrollBar(event.target.scrollLeft)
  1213. }
  1214. this.getElement('tbody').onscroll = function (event) {
  1215. // vm.recalcTrHiddenItem(event.target.scrollTop)
  1216. }
  1217. let { thead, scrollView } = this.$refs
  1218. scrollView.onscroll = function (event) {
  1219. // console.log(event.target.scrollTop, ' - ', event.target.scrollLeft)
  1220. thead.scrollLeft = event.target.scrollLeft
  1221. vm.recalcTrHiddenItem(event.target.scrollTop)
  1222. }
  1223. },
  1224. methods: {
  1225. getElement(id, noCaseId = false) {
  1226. if (!this.el[id]) {
  1227. this.el[id] = document.getElementById((noCaseId ? '' : this.caseId) + id)
  1228. }
  1229. return this.el[id]
  1230. },
  1231. getElementPromise(id, noCaseId = false) {
  1232. return new Promise((resolve) => {
  1233. let timer = setInterval(() => {
  1234. let element = this.getElement(id, noCaseId)
  1235. if (element) {
  1236. clearInterval(timer)
  1237. resolve(element)
  1238. }
  1239. }, 10)
  1240. })
  1241. },
  1242. /** 初始化列表 */
  1243. initialize() {
  1244. this.visibleTrEls = []
  1245. // 判断是否是首次进入该方法,如果是就不清空行,防止删除了预添加的数据
  1246. if (!this.isFirst) {
  1247. // inputValues:用来存储input表单的值
  1248. // 数组里的每项都是一个对象,对象里每个key都是input的rowKey,值就是input的值,其中有个id的字段来区分
  1249. // 示例:
  1250. // [{
  1251. // id: "_jet-4sp0iu-15541771111770"
  1252. // dbDefaultVal: "aaa",
  1253. // dbFieldName: "bbb",
  1254. // dbFieldTxt: "ccc",
  1255. // dbLength: 32
  1256. // }]
  1257. this.inputValues = []
  1258. this.rows = []
  1259. this.deleteIds = []
  1260. this.selectValues = {}
  1261. this.checkboxValues = {}
  1262. this.jdateValues = {}
  1263. this.jInputPopValues = {}
  1264. this.slotValues = {}
  1265. this.selectedRowIds = []
  1266. this.tooltips = {}
  1267. this.notPassedIds = []
  1268. this.uploadValues = []
  1269. this.popupValues = []
  1270. this.popupJshValues = []
  1271. this.radioValues = []
  1272. this.multiSelectValues = []
  1273. this.searchSelectValues = []
  1274. this.scrollTop = 0
  1275. this.$nextTick(() => {
  1276. this.getElement('tbody').scrollTop = 0
  1277. })
  1278. } else {
  1279. this.isFirst = false
  1280. }
  1281. },
  1282. /** 同步滚动条状态 */
  1283. syncScrollBar(scrollLeft) {
  1284. // this.style.tbody.left = `${scrollLeft}px`
  1285. // this.getElement('tbody').scrollLeft = scrollLeft
  1286. },
  1287. /** 重置滚动条位置,参数留空则滚动到上次记录的位置 */
  1288. resetScrollTop(top) {
  1289. let { scrollView } = this.$refs
  1290. if (top != null && typeof top === 'number') {
  1291. scrollView.scrollTop = top
  1292. } else {
  1293. scrollView.scrollTop = this.scrollTop
  1294. }
  1295. },
  1296. /** 重新计算需要隐藏或显示的tr */
  1297. recalcTrHiddenItem(top) {
  1298. let diff = top - this.scrollTop
  1299. if (diff < 0) {
  1300. diff = this.scrollTop - top
  1301. }
  1302. // 只有在滚动了百分之三十的行高的距离时才进行更新
  1303. if (diff >= this.rowHeight * 0.3) {
  1304. this.scrollTop = top
  1305. // 更新form表单的值
  1306. this.$nextTick(() => {
  1307. this.updateFormValues()
  1308. })
  1309. }
  1310. },
  1311. /** 生成id */
  1312. generateId(rows) {
  1313. if (!(rows instanceof Array)) {
  1314. rows = this.rows || []
  1315. }
  1316. let timestamp = new Date().getTime()
  1317. return `${this.caseId}${timestamp}${rows.length}${randomNumber(6)}${this.tempId}`
  1318. },
  1319. /** push 一条数据 */
  1320. push(record, update = true, rows, insertIndex = null, setDefaultValue = true) {
  1321. return this._pushByDataSource([record], [insertIndex], update, rows, setDefaultValue)
  1322. },
  1323. /**
  1324. * push 数据
  1325. *
  1326. * @param dataSource 数据源
  1327. * @param insertIndexes 行插入位置,和dataSource的下标一一对应
  1328. * @param update 是否更新
  1329. * @param rows 若不传就使用 this.rows
  1330. * @param setDefaultValue 是否填充默认值
  1331. *
  1332. */
  1333. _pushByDataSource(dataSource, insertIndexes = null, update = true, rows = null, setDefaultValue = false) {
  1334. if (!(rows instanceof Array)) {
  1335. rows = [...this.rows] || []
  1336. }
  1337. let checkboxValues = { ...this.checkboxValues }
  1338. let selectValues = { ...this.selectValues }
  1339. let jdateValues = { ...this.jdateValues }
  1340. let jInputPopValues = { ...this.jInputPopValues }
  1341. let slotValues = { ...this.slotValues }
  1342. let uploadValues = { ...this.uploadValues }
  1343. let popupValues = { ...this.popupValues }
  1344. let popupJshValues = { ...this.popupJshValues }
  1345. let radioValues = { ...this.radioValues }
  1346. let multiSelectValues = { ...this.multiSelectValues }
  1347. let searchSelectValues = { ...this.searchSelectValues }
  1348. // 禁用行的id
  1349. let disabledRowIds = this.disabledRowIds || []
  1350. dataSource.forEach((data, newValueIndex) => {
  1351. // 不能直接更改数据源的id
  1352. let dataId = data.id
  1353. // 判断源数据是否带有id
  1354. if (dataId == null || dataId === '') {
  1355. dataId = this.generateId(rows)
  1356. } else if (!this.hasCaseId(dataId)) {
  1357. dataId = this.caseId + dataId
  1358. }
  1359. let row = { id: dataId }
  1360. let value = { id: dataId }
  1361. let disabled = false
  1362. this.columns.forEach((column) => {
  1363. let inputId = column.key + value.id
  1364. let sourceValue = data[column.key] == null ? '' : data[column.key]
  1365. let defaultValue = null
  1366. if (setDefaultValue) {
  1367. defaultValue = column.defaultValue || (column.defaultValue === 0 ? 0 : '')
  1368. if (defaultValue instanceof Array) {
  1369. defaultValue = defaultValue.join(',')
  1370. }
  1371. sourceValue = typeof sourceValue === 'number' || sourceValue ? sourceValue : defaultValue
  1372. }
  1373. let sourceValueIsEmpty = sourceValue == null || sourceValue === ''
  1374. if (column.type === FormTypes.inputNumber) {
  1375. // 判断是否是排序字段,如果是就赋最大值
  1376. if (column.isOrder === true) {
  1377. value[column.key] = this.getInputNumberMaxValue(column) + 1
  1378. } else {
  1379. value[column.key] = sourceValue
  1380. }
  1381. // 判断是否是统计列
  1382. if (column.statistics) {
  1383. this.hasStatisticsColumn = true
  1384. if (!this.statisticsColumns[column.key]) {
  1385. this.$set(this.statisticsColumns, column.key, 0)
  1386. }
  1387. }
  1388. } else if (column.type === FormTypes.checkbox) {
  1389. // 判断是否设定了customValue(自定义值)
  1390. if (column.customValue instanceof Array) {
  1391. let customValue = (column.customValue[0] || '').toString()
  1392. if (sourceValueIsEmpty && setDefaultValue) {
  1393. sourceValue = column.defaultChecked ? customValue : sourceValue
  1394. }
  1395. checkboxValues[inputId] = sourceValue === customValue
  1396. } else {
  1397. if (sourceValueIsEmpty && setDefaultValue) {
  1398. checkboxValues[inputId] = !!column.defaultChecked
  1399. } else {
  1400. checkboxValues[inputId] = sourceValue
  1401. }
  1402. }
  1403. } else if (column.type === FormTypes.select) {
  1404. if (!sourceValueIsEmpty) {
  1405. // 判断是否是多选
  1406. if (typeof sourceValue === 'string' && (column.props || {})['mode'] === 'multiple') {
  1407. sourceValue = sourceValue.split(',')
  1408. }
  1409. selectValues[inputId] = sourceValue
  1410. } else {
  1411. selectValues[inputId] = undefined
  1412. }
  1413. } else if (column.type === FormTypes.date || column.type === FormTypes.datetime) {
  1414. jdateValues[inputId] = sourceValue
  1415. } else if (column.type === FormTypes.slot) {
  1416. slotValues[inputId] = sourceValue
  1417. } else if (column.type === FormTypes.popup) {
  1418. popupValues[inputId] = sourceValue
  1419. } else if (column.type === FormTypes.popupJsh) {
  1420. popupJshValues[inputId] = sourceValue
  1421. } else if (column.type === FormTypes.input_pop) {
  1422. jInputPopValues[inputId] = sourceValue
  1423. } else if (column.type === FormTypes.radio) {
  1424. radioValues[inputId] = sourceValue
  1425. } else if (column.type === FormTypes.sel_search) {
  1426. searchSelectValues[inputId] = sourceValue
  1427. } else if (column.type === FormTypes.list_multi) {
  1428. if (typeof sourceValue === 'string' && sourceValue.length > 0) {
  1429. multiSelectValues[inputId] = sourceValue.split(',')
  1430. } else {
  1431. multiSelectValues[inputId] = []
  1432. }
  1433. } else if (
  1434. column.type === FormTypes.upload ||
  1435. column.type === FormTypes.file ||
  1436. column.type === FormTypes.image
  1437. ) {
  1438. if (sourceValue) {
  1439. let fileName = ''
  1440. if (sourceValue.indexOf(',') > 0) {
  1441. let sourceValue2 = sourceValue.split(',')[0]
  1442. fileName = sourceValue2.substring(sourceValue2.lastIndexOf('/') + 1)
  1443. } else {
  1444. fileName = sourceValue.substring(sourceValue.lastIndexOf('/') + 1)
  1445. }
  1446. uploadValues[inputId] = {
  1447. name: fileName,
  1448. status: 'done',
  1449. path: sourceValue,
  1450. }
  1451. }
  1452. } else {
  1453. value[column.key] = sourceValue
  1454. }
  1455. // 解析disabledRows
  1456. for (let columnKey in this.disabledRows) {
  1457. // 判断是否有该属性
  1458. if (this.disabledRows.hasOwnProperty(columnKey) && data.hasOwnProperty(columnKey)) {
  1459. if (disabled !== true) {
  1460. let temp = this.disabledRows[columnKey]
  1461. // 禁用规则可以是一个数组
  1462. if (temp instanceof Array) {
  1463. disabled = temp.includes(data[columnKey])
  1464. } else {
  1465. disabled = temp === data[columnKey]
  1466. }
  1467. if (disabled) {
  1468. disabledRowIds.push(row.id)
  1469. }
  1470. }
  1471. }
  1472. }
  1473. })
  1474. // 插入行而不是添加到最后
  1475. let added = false
  1476. if (insertIndexes instanceof Array) {
  1477. let insertIndex = insertIndexes[newValueIndex]
  1478. if (typeof insertIndex === 'number') {
  1479. added = true
  1480. rows.splice(insertIndex, 0, row)
  1481. this.inputValues.splice(insertIndex, 0, value)
  1482. }
  1483. }
  1484. if (!added) {
  1485. rows.push(row)
  1486. this.inputValues.push(value)
  1487. }
  1488. })
  1489. // 启用了拖动排序,就重新计算排序编号
  1490. if (this.dragSort) {
  1491. this.inputValues.forEach((item, index) => {
  1492. item[this.dragSortKey] = index + 1
  1493. })
  1494. }
  1495. this.disabledRowIds = disabledRowIds
  1496. this.checkboxValues = checkboxValues
  1497. this.selectValues = selectValues
  1498. this.jdateValues = jdateValues
  1499. this.jInputPopValues = jInputPopValues
  1500. this.slotValues = slotValues
  1501. this.uploadValues = uploadValues
  1502. this.popupValues = popupValues
  1503. this.popupJshValues = popupJshValues
  1504. this.radioValues = radioValues
  1505. this.multiSelectValues = multiSelectValues
  1506. this.searchSelectValues = searchSelectValues
  1507. // 重新计算所有统计列
  1508. this.recalcAllStatisticsColumns()
  1509. // 更新到 dom
  1510. if (update) {
  1511. this.rows = rows
  1512. // 更新form表单的值
  1513. this.$nextTick(() => {
  1514. this.updateFormValues()
  1515. })
  1516. }
  1517. return rows
  1518. },
  1519. /** 获取某一数字输入框列中的最大的值 */
  1520. getInputNumberMaxValue(column) {
  1521. let maxNum = 0
  1522. this.inputValues.forEach((item, index) => {
  1523. let val = item[column.key],
  1524. num
  1525. try {
  1526. num = parseInt(val)
  1527. } catch {
  1528. num = 0
  1529. }
  1530. // 把首次循环的结果当成最大值
  1531. if (index === 0) {
  1532. maxNum = num
  1533. } else {
  1534. maxNum = num > maxNum ? num : maxNum
  1535. }
  1536. })
  1537. return maxNum
  1538. },
  1539. /** 添加一行 */
  1540. add(num = 1, forceScrollToBottom = false) {
  1541. if (num < 1) return
  1542. // let timestamp = new Date().getTime()
  1543. let rows = this.rows
  1544. let row
  1545. for (let i = 0; i < num; i++) {
  1546. rows = this.push({}, false, rows)
  1547. row = rows[rows.length - 1]
  1548. }
  1549. this.rows = rows
  1550. this.$nextTick(() => {
  1551. this.updateFormValues()
  1552. })
  1553. // 触发add事件
  1554. this.$emit('added', {
  1555. row: (() => {
  1556. let r = Object.assign({}, row)
  1557. r.id = this.getCleanId(r.id)
  1558. return r
  1559. })(),
  1560. target: this,
  1561. })
  1562. // 设置滚动条位置
  1563. let tbody = this.getElement('tbody')
  1564. let offsetHeight = tbody.offsetHeight
  1565. let realScrollTop = tbody.scrollTop + offsetHeight
  1566. if (forceScrollToBottom === false) {
  1567. // 只有滚动条在底部的时候才自动滚动
  1568. if (!(tbody.scrollHeight - realScrollTop <= 10)) {
  1569. return
  1570. }
  1571. }
  1572. this.$nextTick(() => {
  1573. tbody.scrollTop = tbody.scrollHeight
  1574. })
  1575. this.$nextTick(() => {
  1576. this.autoJumpNextInputBill()
  1577. })
  1578. },
  1579. /**
  1580. * 在指定位置添加一行
  1581. * @param insertIndex 添加位置下标
  1582. * @param num 添加的行数,默认1
  1583. */
  1584. insert(insertIndex, num = 1) {
  1585. if (!insertIndex && num < 1) return
  1586. let rows = this.rows
  1587. let newRows = []
  1588. for (let i = 0; i < num; i++) {
  1589. let row = { id: this.generateId(rows) }
  1590. rows = this.push(row, false, rows, insertIndex)
  1591. newRows.push(row)
  1592. }
  1593. // 同步更改
  1594. this.rows = rows
  1595. this.$nextTick(() => {
  1596. this.recalcSortNumber()
  1597. this.forceUpdateFormValues()
  1598. })
  1599. // 触发 insert 事件
  1600. this.$emit('inserted', {
  1601. rows: newRows.map((row) => {
  1602. let r = cloneObject(row)
  1603. r.id = this.getCleanId(r.id)
  1604. return r
  1605. }),
  1606. num,
  1607. insertIndex,
  1608. target: this,
  1609. })
  1610. this.$nextTick(() => {
  1611. this.autoJumpNextInputBill()
  1612. })
  1613. },
  1614. /** 删除被选中的行 */
  1615. removeSelectedRows() {
  1616. this.removeRows(this.selectedRowIds)
  1617. this.selectedRowIds = []
  1618. },
  1619. /** 删除一行或多行 */
  1620. removeRows(id) {
  1621. let ids = id
  1622. if (!(id instanceof Array)) {
  1623. if (typeof id === 'string') {
  1624. ids = [id]
  1625. } else {
  1626. throw `JEditableTable.removeRows() 函数需要的参数可以是string或Array类型,但提供的却是${typeof id}`
  1627. }
  1628. }
  1629. let rows = cloneObject(this.rows)
  1630. ids.forEach((removeId) => {
  1631. removeId = this.getCleanId(removeId)
  1632. // 找到每个id对应的真实index并删除
  1633. const findAndDelete = (arr) => {
  1634. for (let i = 0; i < arr.length; i++) {
  1635. let currentId = this.getCleanId(arr[i].id)
  1636. if (currentId === removeId) {
  1637. arr.splice(i, 1)
  1638. return true
  1639. }
  1640. }
  1641. }
  1642. // 找到rows对应的index,并删除
  1643. if (findAndDelete(rows)) {
  1644. // 找到values对应的index,并删除
  1645. findAndDelete(this.inputValues)
  1646. // 将caseId去除
  1647. let id = this.getCleanId(removeId)
  1648. this.deleteIds.push(id)
  1649. }
  1650. })
  1651. this.rows = rows
  1652. this.$emit('deleted', this.getDeleteIds(), this)
  1653. this.$nextTick(() => {
  1654. // 更新formValues
  1655. this.updateFormValues()
  1656. // 重新计算统计
  1657. this.recalcAllStatisticsColumns()
  1658. })
  1659. return true
  1660. },
  1661. /** 获取表格表单里的值(异步版) */
  1662. getValuesAsync(options = {}, callback) {
  1663. let { validate, rowIds, deleteTempId } = options
  1664. if (typeof validate !== 'boolean') validate = true
  1665. if (!(rowIds instanceof Array)) rowIds = null
  1666. // 是否删除临时ID,默认为 false
  1667. if (typeof deleteTempId !== 'boolean') deleteTempId = false
  1668. // console.log('options:', { validate, rowIds })
  1669. let asyncCount = 0
  1670. let error = 0
  1671. let inputValues = cloneObject(this.inputValues)
  1672. let tooltips = Object.assign({}, this.tooltips)
  1673. let notPassedIds = cloneObject(this.notPassedIds)
  1674. // 用于存储合并后的值
  1675. let values = []
  1676. // 遍历inputValues来获取每行的值
  1677. for (let value of inputValues) {
  1678. let rowIdsFlag = false
  1679. // 如果带有rowIds,那么就只存这几行的数据
  1680. if (rowIds == null) {
  1681. rowIdsFlag = true
  1682. } else {
  1683. for (let rowId of rowIds) {
  1684. if (this.getCleanId(rowId) === this.getCleanId(value.id)) {
  1685. rowIdsFlag = true
  1686. break
  1687. }
  1688. }
  1689. }
  1690. if (!rowIdsFlag) continue
  1691. this.columns.forEach((column) => {
  1692. let inputId = column.key + value.id
  1693. if (column.type === FormTypes.checkbox) {
  1694. let checked = this.checkboxValues[inputId]
  1695. if (column.customValue instanceof Array) {
  1696. value[column.key] = checked ? column.customValue[0] : column.customValue[1]
  1697. } else {
  1698. value[column.key] = checked
  1699. }
  1700. } else if (column.type === FormTypes.select) {
  1701. let selected = this.selectValues[inputId]
  1702. if (selected instanceof Array) {
  1703. value[column.key] = cloneObject(selected)
  1704. } else {
  1705. value[column.key] = selected
  1706. }
  1707. } else if (column.type === FormTypes.date || column.type === FormTypes.datetime) {
  1708. value[column.key] = this.jdateValues[inputId]
  1709. } else if (column.type === FormTypes.input_pop) {
  1710. value[column.key] = this.jInputPopValues[inputId]
  1711. } else if (column.type === FormTypes.upload) {
  1712. value[column.key] = cloneObject(this.uploadValues[inputId] || null)
  1713. } else if (column.type === FormTypes.image || column.type === FormTypes.file) {
  1714. let currUploadObj = cloneObject(this.uploadValues[inputId] || null)
  1715. if (currUploadObj) {
  1716. value[column.key] = currUploadObj['path'] || null
  1717. }
  1718. } else if (column.type === FormTypes.popup) {
  1719. if (!value[column.key]) {
  1720. value[column.key] = this.popupValues[inputId] || null
  1721. }
  1722. } else if (column.type === FormTypes.popupJsh) {
  1723. if (!value[column.key]) {
  1724. value[column.key] = this.popupJshValues[inputId] || null
  1725. }
  1726. } else if (column.type === FormTypes.radio) {
  1727. value[column.key] = this.radioValues[inputId]
  1728. } else if (column.type === FormTypes.sel_search) {
  1729. value[column.key] = this.searchSelectValues[inputId]
  1730. } else if (column.type === FormTypes.list_multi) {
  1731. if (!this.multiSelectValues[inputId] || this.multiSelectValues[inputId].length === 0) {
  1732. value[column.key] = ''
  1733. } else {
  1734. value[column.key] = this.multiSelectValues[inputId].join(',')
  1735. }
  1736. } else if (column.type === FormTypes.slot) {
  1737. value[column.key] = this.slotValues[inputId]
  1738. }
  1739. // 检查表单验证
  1740. if (validate === true) {
  1741. const handleValidateOneInput = (results) => {
  1742. tooltips[inputId] = results[0]
  1743. if (tooltips[inputId].passed === false) {
  1744. error++
  1745. // if (error++ === 0) {
  1746. // let element = document.getElementById(inputId)
  1747. // while (element.className !== 'tr') {
  1748. // element = element.parentElement
  1749. // }
  1750. // this.jumpToId(inputId, element)
  1751. // }
  1752. }
  1753. tooltips[inputId].visible = false
  1754. notPassedIds = results[1]
  1755. }
  1756. asyncCount++
  1757. let results = this.validateOneInputAsync(
  1758. value[column.key],
  1759. value,
  1760. column,
  1761. notPassedIds,
  1762. false,
  1763. 'getValues',
  1764. (results) => {
  1765. handleValidateOneInput(results)
  1766. asyncCount--
  1767. }
  1768. )
  1769. handleValidateOneInput(results)
  1770. }
  1771. })
  1772. // 删除 tempId
  1773. if (deleteTempId && this.isTempId(value.id)) {
  1774. delete value.id
  1775. } else {
  1776. value.id = this.getCleanId(value.id)
  1777. }
  1778. values.push(value)
  1779. }
  1780. if (validate === true) {
  1781. this.tooltips = tooltips
  1782. this.notPassedIds = notPassedIds
  1783. }
  1784. const timer = setInterval(() => {
  1785. if (asyncCount === 0) {
  1786. clearInterval(timer)
  1787. if (typeof callback === 'function') {
  1788. callback({ error, values })
  1789. }
  1790. }
  1791. }, 10)
  1792. return { error, values }
  1793. },
  1794. /** 获取表格表单里的值(同步版) */
  1795. getValuesSync(options = {}) {
  1796. return this.getValuesAsync(options)
  1797. },
  1798. /** 获取表格表单里的值 */
  1799. getValues(callback, validate = true, rowIds) {
  1800. this.getValuesAsync({ validate, rowIds }, ({ error, values }) => {
  1801. if (typeof callback === 'function') {
  1802. callback(error, values)
  1803. }
  1804. })
  1805. },
  1806. /** getValues的Promise版 */
  1807. getValuesPromise(validate = true, rowIds, deleteTempId) {
  1808. return new Promise((resolve, reject) => {
  1809. this.getValuesAsync({ validate, rowIds, deleteTempId }, ({ error, values }) => {
  1810. if (error === 0) {
  1811. resolve(values)
  1812. } else {
  1813. reject(VALIDATE_NO_PASSED)
  1814. }
  1815. })
  1816. })
  1817. },
  1818. /** 获取被删除项的id */
  1819. getDeleteIds() {
  1820. return cloneObject(this.deleteIds)
  1821. },
  1822. /** 获取所有的数据,包括values、deleteIds */
  1823. getAll(validate, deleteTempId) {
  1824. return new Promise((resolve, reject) => {
  1825. let deleteIds = this.getDeleteIds()
  1826. this.getValuesPromise(validate, null, deleteTempId)
  1827. .then((values) => {
  1828. resolve({ values, deleteIds })
  1829. })
  1830. .catch((error) => {
  1831. reject(error)
  1832. })
  1833. })
  1834. },
  1835. /** Sync 获取所有的数据,包括values、deleteIds */
  1836. getAllSync(validate, rowIds, deleteTempId) {
  1837. let result = this.getValuesSync({ validate, rowIds, deleteTempId })
  1838. result.deleteIds = this.getDeleteIds()
  1839. return result
  1840. },
  1841. // slot 获取值
  1842. _getValueForSlot(rowId) {
  1843. return this.getValuesSync({ rowIds: [rowId] }).values[0]
  1844. },
  1845. _getAllValuesForSlot() {
  1846. return cloneObject({
  1847. inputValues: this.inputValues,
  1848. selectValues: this.selectValues,
  1849. checkboxValues: this.checkboxValues,
  1850. jdateValues: this.jdateValues,
  1851. jInputPopValues: this.jInputPopValues,
  1852. slotValues: this.slotValues,
  1853. uploadValues: this.uploadValues,
  1854. popupValues: this.popupValues,
  1855. popupJshValues: this.popupJshValues,
  1856. radioValues: this.radioValues,
  1857. multiSelectValues: this.multiSelectValues,
  1858. searchSelectValues: this.searchSelectValues,
  1859. })
  1860. },
  1861. /** 设置某行某列的值 */
  1862. setValues(values) {
  1863. values.forEach((item) => {
  1864. let { rowKey, values: newValues } = item
  1865. rowKey = this.getCleanId(rowKey)
  1866. for (let newValueKey in newValues) {
  1867. if (newValues.hasOwnProperty(newValueKey)) {
  1868. let newValue = newValues[newValueKey]
  1869. let edited = false // 已被修改
  1870. this.inputValues.forEach((value) => {
  1871. // 在inputValues中找到了该字段
  1872. if (rowKey === this.getCleanId(value.id)) {
  1873. if (value.hasOwnProperty(newValueKey)) {
  1874. edited = true
  1875. value[newValueKey] = newValue
  1876. }
  1877. }
  1878. })
  1879. let modelKey = `${newValueKey}${this.caseId}${rowKey}`
  1880. // 在 selectValues 中寻找值
  1881. if (!edited) {
  1882. if (newValue !== 0 && !newValue) {
  1883. edited = this.setOneValue(this.selectValues, modelKey, undefined)
  1884. } else {
  1885. edited = this.setOneValue(this.selectValues, modelKey, newValue)
  1886. }
  1887. }
  1888. // 在 checkboxValues 中寻找值
  1889. if (!edited) {
  1890. edited = this.setOneValue(this.checkboxValues, modelKey, newValue)
  1891. }
  1892. // 在 jdateValues 中寻找值
  1893. if (!edited) {
  1894. edited = this.setOneValue(this.jdateValues, modelKey, newValue)
  1895. }
  1896. // 在 jInputPopValues 中寻找值
  1897. if (!edited) {
  1898. edited = this.setOneValue(this.jInputPopValues, modelKey, newValue)
  1899. }
  1900. // 在 slotValues 中寻找值
  1901. if (!edited) {
  1902. edited = this.setOneValue(this.slotValues, modelKey, newValue)
  1903. }
  1904. // 在 uploadValues 中寻找值
  1905. if (!edited) {
  1906. edited = this.setOneValue(this.uploadValues, modelKey, newValue)
  1907. }
  1908. // 在 popupValues 中寻找值
  1909. if (!edited) {
  1910. edited = this.setOneValue(this.popupValues, modelKey, newValue)
  1911. }
  1912. // 在 popupJshValues 中寻找值
  1913. if (!edited) {
  1914. edited = this.setOneValue(this.popupJshValues, modelKey, newValue)
  1915. }
  1916. // 在 radioValues 中寻找值
  1917. if (!edited) {
  1918. edited = this.setOneValue(this.radioValues, modelKey, newValue)
  1919. }
  1920. // 在 multiSelectValues 中寻找值
  1921. if (!edited) {
  1922. edited = this.setOneValue(this.multiSelectValues, modelKey, newValue)
  1923. }
  1924. // 在 searchSelectValues 中寻找值
  1925. if (!edited) {
  1926. edited = this.setOneValue(this.searchSelectValues, modelKey, newValue)
  1927. }
  1928. }
  1929. }
  1930. })
  1931. // 强制更新formValues
  1932. this.forceUpdateFormValues()
  1933. },
  1934. setOneValue(valuesObject, modelKey, value) {
  1935. let key = this.valuesHasOwnProperty(valuesObject, modelKey)
  1936. if (key) {
  1937. this.$set(valuesObject, key, value)
  1938. return true
  1939. }
  1940. return false
  1941. },
  1942. valuesHasOwnProperty(values, ownProperty) {
  1943. let key = ownProperty
  1944. if (values.hasOwnProperty(key)) {
  1945. return key
  1946. }
  1947. if (values.hasOwnProperty(key + this.tempId)) {
  1948. return key + this.tempId
  1949. }
  1950. return null
  1951. },
  1952. /** 跳转到指定位置 */
  1953. // jumpToId(id, element) {
  1954. // if (element == null) {
  1955. // element = document.getElementById(id)
  1956. // }
  1957. // if (element != null) {
  1958. // console.log(this.getElement('tbody').scrollTop, element.offsetTop)
  1959. // this.getElement('tbody').scrollTop = element.offsetTop
  1960. // console.log(this.getElement('tbody').scrollTop, element.offsetTop)
  1961. // }
  1962. // },
  1963. /**
  1964. * 验证单个表单,异步版
  1965. *
  1966. * @param value 校验的值
  1967. * @param row 校验的行
  1968. * @param column 校验的列
  1969. * @param notPassedIds 没有通过校验的 id
  1970. * @param update 是否更新到vue中
  1971. * @param validType 校验触发的方式(input、blur等)
  1972. * @param callback
  1973. */
  1974. validateOneInputAsync(value, row, column, notPassedIds, update = false, validType = 'input', callback) {
  1975. let tooltips = Object.assign({}, this.tooltips)
  1976. // let notPassedIds = cloneObject(this.notPassedIds)
  1977. let inputId = column.key + row.id
  1978. tooltips[inputId] = tooltips[inputId] ? tooltips[inputId] : {}
  1979. let [passed, message] = this.validateValue(column, value)
  1980. const nextThen = (res) => {
  1981. let [passed, message] = res
  1982. // !(passed == null && tooltips[inputId].visible != null)
  1983. if (passed != null) {
  1984. tooltips[inputId].visible = !passed
  1985. tooltips[inputId].passed = passed
  1986. let index = notPassedIds.indexOf(inputId)
  1987. let borderColor = null,
  1988. boxShadow = null
  1989. if (!passed) {
  1990. tooltips[inputId].title = this.replaceProps(column, message)
  1991. borderColor = 'red'
  1992. boxShadow = `0 0 0 2px rgba(255, 0, 0, 0.2)`
  1993. if (index === -1) notPassedIds.push(inputId)
  1994. } else {
  1995. if (index !== -1) notPassedIds.splice(index, 1)
  1996. }
  1997. let element = document.getElementById(inputId)
  1998. if (element != null) {
  1999. // select 在 .ant-select-selection 上设置 border-color
  2000. if (column.type === FormTypes.select) {
  2001. element = element.getElementsByClassName('ant-select-selection')[0]
  2002. }
  2003. // jdate 在 input 上设置 border-color
  2004. if (column.type === FormTypes.date || column.type === FormTypes.datetime) {
  2005. element = element.getElementsByTagName('input')[0]
  2006. }
  2007. // upload 在 .ant-upload .ant-btn 上设置 border-color
  2008. if (column.type === FormTypes.upload || column.type === FormTypes.file || column.type === FormTypes.image) {
  2009. element = element.getElementsByClassName('ant-upload')[0].getElementsByClassName('ant-btn')[0]
  2010. }
  2011. element.style.borderColor = borderColor
  2012. element.style.boxShadow = boxShadow
  2013. if (element.tagName === 'SPAN') {
  2014. element.style.display = 'block'
  2015. }
  2016. }
  2017. }
  2018. // 是否更新到data
  2019. if (update) {
  2020. this.tooltips = tooltips
  2021. this.notPassedIds = notPassedIds
  2022. }
  2023. if (typeof callback === 'function') {
  2024. callback([tooltips[inputId], notPassedIds])
  2025. }
  2026. }
  2027. if (typeof passed === 'function') {
  2028. let executed = false
  2029. passed(
  2030. validType,
  2031. value,
  2032. { id: this.getCleanId(row.id) },
  2033. { ...column },
  2034. (flag, msg) => {
  2035. if (executed) return
  2036. executed = true
  2037. if (typeof msg === 'string') {
  2038. message = msg
  2039. }
  2040. if (flag == null) {
  2041. nextThen([null, message])
  2042. } else {
  2043. nextThen([!!flag, message])
  2044. }
  2045. },
  2046. this
  2047. )
  2048. } else {
  2049. nextThen([passed, message])
  2050. }
  2051. return [tooltips[inputId], notPassedIds]
  2052. },
  2053. /** 验证单个表单 */
  2054. validateOneInput(value, row, column, notPassedIds, update = false, validType = 'input') {
  2055. return this.validateOneInputAsync(value, row, column, notPassedIds, update, validType)
  2056. },
  2057. /** 通过规则验证值是否正确 */
  2058. validateValue(column, value) {
  2059. let rules = column.validateRules
  2060. let passed = true,
  2061. message = ''
  2062. // 判断有没有验证规则或验证规则格式正不正确,若条件不符合则默认通过
  2063. if (rules instanceof Array) {
  2064. for (let rule of rules) {
  2065. // 当前值是否为空
  2066. let isNull = value == null || value === ''
  2067. // 验证规则:非空
  2068. if (rule.required === true && isNull) {
  2069. passed = false
  2070. } // 使用 else-if 是为了防止一个 rule 中出现两个规则
  2071. // 验证规则:唯一校验
  2072. else if (rule.unique === true || rule.pattern === 'only') {
  2073. let { values } = this.getValuesSync({ validate: false })
  2074. let findCount = 0
  2075. for (let val of values) {
  2076. if (val[column.key] === value) {
  2077. if (++findCount >= 2) {
  2078. passed = false
  2079. break
  2080. }
  2081. }
  2082. }
  2083. }
  2084. // 验证规则:正则表达式
  2085. else if (!!rule.pattern && !isNull) {
  2086. // 兼容 online 的规则
  2087. let foo = [
  2088. { title: '6到16位数字', value: 'n6-16', pattern: /^\d{6,18}$/ },
  2089. { title: '6到16位任意字符', value: '*6-16', pattern: /^.{6,16}$/ },
  2090. { title: '6到18位字母', value: 's6-18', pattern: /^[a-z|A-Z]{6,18}$/ },
  2091. {
  2092. title: '网址',
  2093. value: 'url',
  2094. pattern:
  2095. /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/,
  2096. },
  2097. { title: '电子邮件', value: 'e', pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/ },
  2098. { title: '手机号码', value: 'm', pattern: /^1[3456789]\d{9}$/ },
  2099. { title: '邮政编码', value: 'p', pattern: /^[1-9]\d{5}$/ },
  2100. { title: '字母', value: 's', pattern: /^[A-Z|a-z]+$/ },
  2101. { title: '数字', value: 'n', pattern: /^-?\d+(\.?\d+|\d?)$/ },
  2102. { title: '整数', value: 'z', pattern: /^-?\d+$/ },
  2103. { title: '非空', value: '*', pattern: /^.+$/ },
  2104. { title: '金额', value: 'money', pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/ },
  2105. ]
  2106. let flag = false
  2107. for (let item of foo) {
  2108. if (rule.pattern === item.value && item.pattern) {
  2109. passed = new RegExp(item.pattern).test(value)
  2110. flag = true
  2111. break
  2112. }
  2113. }
  2114. if (!flag) passed = new RegExp(rule.pattern).test(value)
  2115. }
  2116. // 校验规则:自定义函数校验
  2117. else if (typeof rule.handler === 'function') {
  2118. return [rule.handler, rule.message]
  2119. }
  2120. // 如果没有通过验证,则跳出循环。如果通过了验证,则继续验证下一条规则
  2121. if (!passed) {
  2122. message = rule.message
  2123. break
  2124. }
  2125. }
  2126. }
  2127. return [passed, message]
  2128. },
  2129. /** 动态更新表单的值 */
  2130. updateFormValues() {
  2131. let trs = this.getElement('tbody').getElementsByClassName('tr')
  2132. let trEls = []
  2133. for (let tr of trs) {
  2134. trEls.push(tr)
  2135. }
  2136. // 获取新增的 tr
  2137. let newTrEls = trEls
  2138. if (this.visibleTrEls.length > 0) {
  2139. newTrEls = []
  2140. for (let tr of trEls) {
  2141. let isNewest = true
  2142. for (let vtr of this.visibleTrEls) {
  2143. if (vtr.id === tr.id) {
  2144. isNewest = false
  2145. break
  2146. }
  2147. }
  2148. if (isNewest) {
  2149. newTrEls.push(tr)
  2150. }
  2151. }
  2152. }
  2153. this.visibleTrEls = trEls
  2154. // 向新增的tr中赋值
  2155. newTrEls.forEach((tr) => {
  2156. let { idx } = tr.dataset
  2157. let value = this.inputValues[idx]
  2158. for (let key in value) {
  2159. if (value.hasOwnProperty(key)) {
  2160. let elid = `${key}${value.id}`
  2161. let el = document.getElementById(elid)
  2162. if (el) {
  2163. el.value = value[key]
  2164. }
  2165. }
  2166. }
  2167. })
  2168. },
  2169. /** 强制更新FormValues */
  2170. forceUpdateFormValues() {
  2171. this.visibleTrEls = []
  2172. this.updateFormValues()
  2173. },
  2174. // 重新计算所有统计列
  2175. recalcAllStatisticsColumns() {
  2176. if (this.hasStatisticsColumn) {
  2177. Object.keys(this.statisticsColumns).forEach((key) => this.recalcOneStatisticsColumn(key))
  2178. }
  2179. },
  2180. // 重新计算单个统计列
  2181. recalcOneStatisticsColumn(key) {
  2182. if (this.hasStatisticsColumn) {
  2183. if (this.statisticsColumns.hasOwnProperty(key)) {
  2184. // 计算合计值
  2185. let count = 0
  2186. this.inputValues.forEach((item) => {
  2187. let value = item[key]
  2188. if (value && count !== '-') {
  2189. try {
  2190. count += Number.parseFloat(value)
  2191. } catch (e) {
  2192. count = '-'
  2193. }
  2194. }
  2195. })
  2196. this.statisticsColumns[key] = count.toFixed(2)
  2197. }
  2198. }
  2199. },
  2200. /** 获取某个统计字段的值 */
  2201. getStatisticsValue(key) {
  2202. if (this.hasStatisticsColumn) {
  2203. if (this.statisticsColumns.hasOwnProperty(key)) {
  2204. return this.statisticsColumns[key]
  2205. }
  2206. }
  2207. return null
  2208. },
  2209. /** 全选或取消全选 */
  2210. handleChangeCheckedAll() {
  2211. let selectedRowIds = []
  2212. if (!this.getSelectAll) {
  2213. this.rows.forEach((row) => {
  2214. if ((this.disabledRowIds || []).indexOf(row.id) === -1) {
  2215. selectedRowIds.push(row.id)
  2216. }
  2217. })
  2218. }
  2219. this.selectedRowIds = selectedRowIds
  2220. },
  2221. /** 左侧行选择框change事件 */
  2222. handleChangeLeftCheckbox(event) {
  2223. let { id } = event.target
  2224. if ((this.disabledRowIds || []).indexOf(id) !== -1) {
  2225. return
  2226. }
  2227. let index = this.selectedRowIds.indexOf(id)
  2228. if (index !== -1) {
  2229. this.selectedRowIds.splice(index, 1)
  2230. } else {
  2231. this.selectedRowIds.push(id)
  2232. }
  2233. },
  2234. handleClickAdd() {
  2235. this.add()
  2236. },
  2237. handleConfirmDelete() {
  2238. this.removeSelectedRows()
  2239. },
  2240. handleClickClearSelection() {
  2241. this.clearSelection()
  2242. },
  2243. clearSelection() {
  2244. this.selectedRowIds = []
  2245. },
  2246. /** 用于搜索下拉框中的内容 */
  2247. handleSelectFilterOption(input, option, column) {
  2248. if (column.allowSearch === true || column.allowInput === true) {
  2249. return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  2250. }
  2251. return true
  2252. },
  2253. /** select 搜索时的事件,用于动态添加options */
  2254. handleSearchSelect(value, id, row, col) {
  2255. if (col.allowSearch !== true && col.allowInput === true) {
  2256. // 是否找到了对应的项,找不到则添加这一项
  2257. let flag = false
  2258. for (let option of col.options) {
  2259. if (option.value.toLocaleString() === value.toLocaleString()) {
  2260. flag = true
  2261. break
  2262. }
  2263. }
  2264. // !!value :不添加空值
  2265. if (!flag && !!value) {
  2266. // searchAdd 是否是通过搜索添加的
  2267. col.options.push({ title: value, value: value, searchAdd: true })
  2268. }
  2269. }
  2270. },
  2271. //获取焦点
  2272. handleFocusSearch(value, id, row, col) {
  2273. this.validateOneInput(value, row, col, this.notPassedIds, true, 'focus')
  2274. this.elemValueChange('unit', row, col, value)
  2275. },
  2276. // blur 失去焦点
  2277. handleBlurSearch(value, id, row, col) {
  2278. if (col.allowInput === true) {
  2279. // 删除无用的因搜索(用户输入)而创建的项
  2280. if (typeof value === 'string') {
  2281. let indexs = []
  2282. col.options.forEach((option, index) => {
  2283. if (option.value.toLocaleString() === value.toLocaleString()) {
  2284. delete option.searchAdd
  2285. } else if (option.searchAdd === true) {
  2286. indexs.push(index)
  2287. }
  2288. })
  2289. // 翻转删除数组中的项
  2290. for (let index of indexs.reverse()) {
  2291. col.options.splice(index, 1)
  2292. }
  2293. }
  2294. }
  2295. // 做单个表单验证
  2296. this.validateOneInput(value, row, col, this.notPassedIds, true, 'blur')
  2297. },
  2298. /** 触发已拖动事件 */
  2299. emitDragged(oldIndex, newIndex) {
  2300. this.$emit('dragged', { oldIndex, newIndex, target: this })
  2301. },
  2302. handleDragMoveStart(event) {
  2303. this.dragging = true
  2304. this.$refs.scrollView.style.overflow = 'hidden'
  2305. },
  2306. /** 拖动结束,交换inputValue中的值 */
  2307. handleDragMoveEnd(event) {
  2308. this.dragging = false
  2309. this.$refs.scrollView.style.overflow = 'auto'
  2310. let {
  2311. oldIndex,
  2312. newIndex,
  2313. item: {
  2314. dataset: { idx: dataIdx },
  2315. },
  2316. } = event
  2317. // 由于动态显示隐藏行导致index有误差,需要算出真实的index
  2318. let diff = Number.parseInt(dataIdx) - oldIndex
  2319. oldIndex += diff
  2320. newIndex += diff
  2321. this.rowResort(oldIndex, newIndex)
  2322. this.emitDragged(oldIndex, newIndex)
  2323. },
  2324. /** 行重新排序 */
  2325. rowResort(oldIndex, newIndex) {
  2326. const sort = (array) => {
  2327. // 存储旧数据,并删除旧项目
  2328. let temp = array[oldIndex]
  2329. array.splice(oldIndex, 1)
  2330. // 向新项目里添加旧数据
  2331. array.splice(newIndex, 0, temp)
  2332. }
  2333. sort(this.rows)
  2334. sort(this.inputValues)
  2335. this.recalcSortNumber()
  2336. this.forceUpdateFormValues()
  2337. },
  2338. /** 重新计算排序字段的数值 */
  2339. recalcSortNumber() {
  2340. if (this.dragSort) {
  2341. // 重置排序字段
  2342. this.inputValues.forEach((val, idx) => (val[this.dragSortKey] = idx + 1))
  2343. }
  2344. },
  2345. /** 当前行向上移一位 */
  2346. _handleRowMoveUp(rowIndex) {
  2347. if (rowIndex > 0) {
  2348. let newIndex = rowIndex - 1
  2349. this.rowResort(rowIndex, newIndex)
  2350. this.emitDragged(rowIndex, newIndex)
  2351. }
  2352. },
  2353. /** 当前行向下移一位 */
  2354. _handleRowMoveDown(rowIndex) {
  2355. if (rowIndex < this.rows.length - 1) {
  2356. let newIndex = rowIndex + 1
  2357. this.rowResort(rowIndex, newIndex)
  2358. this.emitDragged(rowIndex, newIndex)
  2359. }
  2360. },
  2361. /** 在当前行下面插入一行 */
  2362. _handleRowInsertDown(rowIndex) {
  2363. let insertIndex = rowIndex + 1
  2364. this.insert(insertIndex)
  2365. },
  2366. /* --- common function begin --- */
  2367. /** 鼠标移入 */
  2368. handleMouseoverCommono(row, column) {
  2369. let inputId = column.key + row.id
  2370. if (this.notPassedIds.indexOf(inputId) !== -1) {
  2371. this.showOrHideTooltip(inputId, true, true)
  2372. }
  2373. },
  2374. /** 鼠标移出 */
  2375. handleMouseoutCommono(row, column) {
  2376. let inputId = column.key + row.id
  2377. this.showOrHideTooltip(inputId, false)
  2378. },
  2379. /** input事件 */
  2380. handleInputCommono(target, index, row, column) {
  2381. let oldValue = this.inputValues[index][column.key] || ''
  2382. let { value, dataset, selectionStart } = target
  2383. let type = FormTypes.input
  2384. let change = true
  2385. if (`${dataset.inputNumber}` === 'true') {
  2386. type = FormTypes.inputNumber
  2387. // 判断输入的值是否匹配数字正则表达式,不匹配就还原
  2388. if (!/^-?\d+\.?\d*$/.test(value) && value !== '' && value !== '-') {
  2389. change = false
  2390. value = oldValue
  2391. target.value = value
  2392. if (typeof selectionStart === 'number') {
  2393. target.selectionStart = selectionStart - 1
  2394. target.selectionEnd = selectionStart - 1
  2395. }
  2396. }
  2397. }
  2398. // 存储输入的值
  2399. this.inputValues[index][column.key] = value
  2400. // 做单个表单验证
  2401. this.validateOneInput(value, row, column, this.notPassedIds, true, 'input')
  2402. if (type === FormTypes.inputNumber) {
  2403. this.recalcOneStatisticsColumn(column.key)
  2404. }
  2405. // 触发valueChange 事件
  2406. if (change) {
  2407. this.elemValueChange(type, row, column, value)
  2408. }
  2409. },
  2410. /** slot Change */
  2411. handleChangeSlotCommon(value, id, row, column) {
  2412. this.slotValues = this.bindValuesChange(value, id, 'slotValues')
  2413. // 做单个表单验证
  2414. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2415. // 触发valueChange 事件
  2416. this.elemValueChange(FormTypes.slot, row, column, value)
  2417. },
  2418. handleFocusSlotCommon(value, id, row, column) {
  2419. // this.slotValues = this.bindValuesChange(value, id, 'slotValues')
  2420. // // 做单个表单验证
  2421. this.validateOneInput(value, row, column, this.notPassedIds, true, 'focus')
  2422. // // 触发valueChange 事件
  2423. this.elemFocusChange(FormTypes.slot, row, column, value)
  2424. },
  2425. //获取焦点时触发
  2426. elemFocusChange(type, rowSource, columnSource, value) {
  2427. let unitList = []
  2428. let column = Object.assign({}, columnSource)
  2429. // 将caseId去除
  2430. let row = Object.assign({}, rowSource)
  2431. row.id = this.getCleanId(row.id)
  2432. // 获取整行的数据
  2433. let { values } = this.getValuesSync({ validate: false, rowIds: [row.id] })
  2434. if (values.length > 0) {
  2435. Object.assign(row, values[0])
  2436. }
  2437. if (!row.unitId) {
  2438. unitList = []
  2439. }
  2440. let arr = row.unitList
  2441. if (arr && !Array.isArray(arr)) {
  2442. unitList = JSON.parse(arr)
  2443. }
  2444. column.options = unitList
  2445. this.$emit('focusChange', unitList)
  2446. },
  2447. handleBlurCommono(target, index, row, column) {
  2448. let { value, dataset } = target
  2449. if (dataset && `${dataset.inputNumber}` === 'true') {
  2450. // 判断输入的值是否匹配数字正则表达式,不匹配就置空
  2451. if (!/^-?\d+\.?\d*$/.test(value)) {
  2452. value = ''
  2453. } else {
  2454. value = Number.parseFloat(value)
  2455. }
  2456. target.value = value
  2457. }
  2458. // 做单个表单验证
  2459. this.validateOneInput(value, row, column, this.notPassedIds, true, 'blur')
  2460. },
  2461. handleChangeCheckboxCommon(event, row, column) {
  2462. let { id, checked } = event.target
  2463. this.checkboxValues = this.bindValuesChange(checked, id, 'checkboxValues')
  2464. // 触发valueChange 事件
  2465. this.elemValueChange(FormTypes.checkbox, row, column, checked)
  2466. },
  2467. handleChangeSelectCommon(value, id, row, column) {
  2468. this.selectValues = this.bindValuesChange(value, id, 'selectValues')
  2469. // 做单个表单验证
  2470. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2471. // 触发valueChange 事件
  2472. this.elemValueChange(FormTypes.select, row, column, value)
  2473. },
  2474. handleChangePopupJshCommon(value, id, row, column, index) {
  2475. this.popupJshValues = this.bindValuesChange(value, id, 'popupJshValues')
  2476. // 做单个表单验证
  2477. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2478. // 触发valueChange 事件
  2479. this.elemValueChange(FormTypes.popupJsh, row, column, value)
  2480. },
  2481. handleChangeJDateCommon(value, id, row, column, showTime) {
  2482. this.jdateValues = this.bindValuesChange(value, id, 'jdateValues')
  2483. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2484. // 触发valueChange 事件
  2485. if (showTime) {
  2486. this.elemValueChange(FormTypes.datetime, row, column, value)
  2487. } else {
  2488. this.elemValueChange(FormTypes.date, row, column, value)
  2489. }
  2490. },
  2491. handleChangeJInputPopCommon(value, id, row, column) {
  2492. this.jInputPopValues = this.bindValuesChange(value, id, 'jInputPopValues')
  2493. // 做单个表单验证
  2494. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2495. // 触发valueChange 事件
  2496. this.elemValueChange(FormTypes.input_pop, row, column, value)
  2497. },
  2498. handleChangeUpload(info, id, row, column) {
  2499. let { file } = info
  2500. let value = {
  2501. name: file.name,
  2502. type: file.type,
  2503. size: file.size,
  2504. status: file.status,
  2505. percent: file.percent,
  2506. }
  2507. if (column.responseName && file.response) {
  2508. value['responseName'] = file.response[column.responseName]
  2509. }
  2510. if (file.status === 'done') {
  2511. value['path'] = file.response[column.responseName]
  2512. } else if (file.status === 'error') {
  2513. value['message'] = file.response.message || '未知错误'
  2514. }
  2515. this.uploadValues = this.bindValuesChange(value, id, 'uploadValues')
  2516. },
  2517. handleMoreOperation(id, flag) {
  2518. //console.log("this.uploadValues[id]",this.uploadValues[id])
  2519. let path = ''
  2520. if (this.uploadValues && this.uploadValues[id]) {
  2521. path = this.uploadValues[id].path
  2522. }
  2523. this.$refs.filePop.show(id, path, flag)
  2524. },
  2525. handleFileSuccess(obj) {
  2526. if (obj.id) {
  2527. this.uploadValues = this.bindValuesChange(obj, obj.id, 'uploadValues')
  2528. }
  2529. },
  2530. /** 记录用到数据绑定的组件的值 */
  2531. bindValuesChange(value, id, key) {
  2532. // let values = Object.assign({}, this[key])
  2533. // values[id] = value
  2534. // return values
  2535. this.$set(this[key], id, value)
  2536. return this[key]
  2537. },
  2538. /** 显示或隐藏tooltip */
  2539. showOrHideTooltip(inputId, show, force = false) {
  2540. if (!this.tooltips[inputId] && !force) {
  2541. return
  2542. }
  2543. let tooltip = this.tooltips[inputId] || {}
  2544. if (tooltip.visible !== show) {
  2545. tooltip.visible = show
  2546. this.$set(this.tooltips, inputId, tooltip)
  2547. }
  2548. },
  2549. /** value 触发valueChange事件 */
  2550. elemValueChange(type, rowSource, columnSource, value) {
  2551. let column = Object.assign({}, columnSource)
  2552. // 将caseId去除
  2553. let row = Object.assign({}, rowSource)
  2554. row.id = this.getCleanId(row.id)
  2555. // 获取整行的数据
  2556. let { values } = this.getValuesSync({ validate: false, rowIds: [row.id] })
  2557. if (values.length > 0) {
  2558. Object.assign(row, values[0])
  2559. }
  2560. this.$emit('valueChange', { type, row, column, value, target: this })
  2561. },
  2562. /** 获取干净的ID(不包含任何杂质的ID) */
  2563. getCleanId(id) {
  2564. id = this.removeCaseId(id)
  2565. id = this.removeTempId(id)
  2566. return id
  2567. },
  2568. /** 判断某个ID是否包含了caseId */
  2569. hasCaseId(id) {
  2570. id = id + ''
  2571. return id && id.startsWith(this.caseId)
  2572. },
  2573. /** 将caseId去除 */
  2574. removeCaseId(id) {
  2575. if (this.hasCaseId(id)) {
  2576. return id.substring(this.caseId.length, id.length)
  2577. }
  2578. return id
  2579. },
  2580. // 判断 id 是否是临时Id
  2581. isTempId(id) {
  2582. return (id || '').endsWith(this.tempId)
  2583. },
  2584. /** 将tempId去除 */
  2585. removeTempId(id) {
  2586. if (this.isTempId(id)) {
  2587. return id.substring(0, id.length - this.tempId.length)
  2588. }
  2589. return id
  2590. },
  2591. handleClickDelFile(id) {
  2592. this.uploadValues[id] = null
  2593. },
  2594. handleClickDownloadFile(id) {
  2595. let { path } = this.uploadValues[id] || {}
  2596. if (path) {
  2597. let url = getFileAccessHttpUrl(path)
  2598. window.open(url)
  2599. }
  2600. },
  2601. handleClickDownFileByUrl(id) {
  2602. let { url, path } = this.uploadValues[id] || {}
  2603. if (!url || url.length === 0) {
  2604. if (path && path.length > 0) {
  2605. url = getFileAccessHttpUrl(path.split(',')[0])
  2606. }
  2607. }
  2608. if (url) {
  2609. window.open(url)
  2610. }
  2611. },
  2612. handleClickShowImageError(id) {
  2613. let currUploadObj = this.uploadValues[id] || null
  2614. if (currUploadObj && currUploadObj['message']) {
  2615. this.$error({ title: '上传出错', content: '错误信息:' + currUploadObj['message'], maskClosable: true })
  2616. }
  2617. },
  2618. /* --- common function end --- */
  2619. /* --- 以下是辅助方法,多用于动态构造页面中的数据 --- */
  2620. /** 辅助方法:打印日志 */
  2621. log() {
  2622. if (this.$attrs.logger) {
  2623. console.log.apply(null, arguments)
  2624. }
  2625. },
  2626. getVM() {
  2627. return this
  2628. },
  2629. /** 辅助方法:指定a-select 和 j-data 的父容器 */
  2630. getParentContainer(node) {
  2631. let element = (() => {
  2632. // nodeType 8 : Comment : 注释
  2633. if (this.$el && this.$el.nodeType !== 8) {
  2634. return this.$el
  2635. }
  2636. let doc = document.getElementById(this.caseId + 'inputTable')
  2637. if (doc != null) {
  2638. return doc
  2639. }
  2640. return node.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode
  2641. })()
  2642. // 递归判断是否带有 overflow: hidden;的父元素
  2643. const ifParent = (child) => {
  2644. let currentOverflow = null
  2645. if (child['currentStyle']) {
  2646. currentOverflow = child['currentStyle']['overflow']
  2647. } else if (window.getComputedStyle) {
  2648. currentOverflow = window.getComputedStyle(child)['overflow']
  2649. }
  2650. if (currentOverflow != null) {
  2651. if (currentOverflow === 'hidden') {
  2652. // 找到了带有 hidden 的标签,判断它的父级是否还有 hidden,直到遇到完全没有 hidden 或 body 的时候才停止递归
  2653. let temp = ifParent(child.parentNode)
  2654. return temp != null ? temp : child.parentNode
  2655. }
  2656. // 当前标签没有 hidden ,如果有父级并且父级不是 body 的话就继续递归判断父级
  2657. else if (child.parentNode && child.parentNode.tagName.toLocaleLowerCase() !== 'body') {
  2658. return ifParent(child.parentNode)
  2659. } else {
  2660. // 直到 body 都没有遇到有 hidden 的标签
  2661. return null
  2662. }
  2663. } else {
  2664. return child
  2665. }
  2666. }
  2667. let temp = ifParent(element)
  2668. return temp != null ? temp : element
  2669. },
  2670. /** 辅助方法:替换${...}变量 */
  2671. replaceProps(col, value) {
  2672. if (value && typeof value === 'string') {
  2673. value = value.replace(/\${title}/g, col.title)
  2674. value = value.replace(/\${key}/g, col.key)
  2675. value = value.replace(/\${defaultValue}/g, col.defaultValue)
  2676. }
  2677. return value
  2678. },
  2679. /** view辅助方法:构建 tr style */
  2680. buildTrStyle(index) {
  2681. return {
  2682. top: `${rowHeight * index}px`,
  2683. }
  2684. },
  2685. /** view辅助方法:构建 td style */
  2686. buildTdStyle(col) {
  2687. const isEmptyWidth = (column) =>
  2688. column.type === FormTypes.hidden || column.width === '0px' || column.width === '0' || column.width === 0
  2689. let style = {}
  2690. // 计算宽度
  2691. if (col.width) {
  2692. style['width'] = col.width
  2693. } else if (this.columns) {
  2694. style['width'] = `${(100 - 4 * 2) / this.columns.filter((column) => !isEmptyWidth(column)).length}%`
  2695. } else {
  2696. style['width'] = '120px'
  2697. }
  2698. // checkbox 居中显示
  2699. let isCheckbox = col.type === FormTypes.checkbox
  2700. if (isCheckbox) {
  2701. style['align-items'] = 'center'
  2702. style['text-align'] = 'center'
  2703. style['padding-left'] = '0'
  2704. style['padding-right'] = '0'
  2705. }
  2706. if (isEmptyWidth(col)) {
  2707. style['padding-left'] = '0'
  2708. style['padding-right'] = '0'
  2709. }
  2710. return style
  2711. },
  2712. /** view辅助方法:构造props */
  2713. buildProps(row, col) {
  2714. let props = {}
  2715. // 解析props
  2716. if (typeof col.props === 'object') {
  2717. for (let prop in col.props) {
  2718. if (col.props.hasOwnProperty(prop)) {
  2719. props[prop] = this.replaceProps(col, col.props[prop])
  2720. }
  2721. }
  2722. }
  2723. // 判断select是否允许输入
  2724. if (col.type === FormTypes.select && (col.allowInput === true || col.allowSearch === true)) {
  2725. props['showSearch'] = true
  2726. }
  2727. // 判断是否是禁用的列
  2728. props['disabled'] = typeof col['disabled'] === 'boolean' ? col['disabled'] : props['disabled']
  2729. // 判断是否为禁用的行
  2730. if (props['disabled'] !== true) {
  2731. props['disabled'] = (this.disabledRowIds || []).indexOf(row.id) !== -1
  2732. }
  2733. // 判断是否禁用全部组件
  2734. if (this.disabled === true) {
  2735. props['disabled'] = true
  2736. }
  2737. return props
  2738. },
  2739. /** upload 辅助方法:获取 headers */
  2740. uploadGetHeaders(row, column) {
  2741. let headers = {}
  2742. if (column.token === true) {
  2743. headers['X-Access-Token'] = this.accessToken
  2744. }
  2745. return headers
  2746. },
  2747. /** 上传请求地址 */
  2748. getUploadAction(value) {
  2749. if (!value) {
  2750. return window._CONFIG['domianURL'] + '/sys/common/upload'
  2751. } else {
  2752. return value
  2753. }
  2754. },
  2755. /** 预览图片地址 */
  2756. getCellImageView(id) {
  2757. let currUploadObj = this.uploadValues[id] || null
  2758. if (currUploadObj) {
  2759. if (currUploadObj['url']) {
  2760. return currUploadObj['url']
  2761. } else if (currUploadObj['path']) {
  2762. let readpath = currUploadObj['path'].split(',')[0]
  2763. return getFileAccessHttpUrl(readpath)
  2764. }
  2765. }
  2766. return ''
  2767. },
  2768. /** popup回调 */
  2769. popupCallback(value, others, id, row, column, index) {
  2770. // 存储输入的值
  2771. this.popupValues[id] = value
  2772. if (others) {
  2773. Object.keys(others).map((key) => {
  2774. this.columns.map((k) => {
  2775. if (k.key === key) {
  2776. let tempId = id.substring(id.indexOf(this.caseIdPrefix))
  2777. if (k.type === 'date') {
  2778. this.handleChangeJDateCommon(others[key], key + tempId, { id: tempId }, k, false)
  2779. } else if (k.type === 'datetime') {
  2780. this.handleChangeJDateCommon(others[key], key + tempId, { id: tempId }, k, true)
  2781. } else {
  2782. this.inputValues[index][key] = others[key]
  2783. }
  2784. }
  2785. })
  2786. })
  2787. }
  2788. // 做单个表单验证
  2789. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2790. // 触发valueChange 事件
  2791. this.elemValueChange('input', row, column, value)
  2792. // 更新form表单的值
  2793. this.$nextTick(() => {
  2794. this.forceUpdateFormValues()
  2795. })
  2796. },
  2797. /** popupJsh回调 */
  2798. popupJshCallback(value, others, id, row, column, index) {
  2799. // 存储输入的值
  2800. this.popupJshValues[id] = value
  2801. if (others) {
  2802. Object.keys(others).map((key) => {
  2803. this.columns.map((k) => {
  2804. if (k.key === key) {
  2805. let tempId = id.substring(id.indexOf(this.caseIdPrefix))
  2806. if (k.type === 'date') {
  2807. this.handleChangeJDateCommon(others[key], key + tempId, { id: tempId }, k, false)
  2808. } else if (k.type === 'datetime') {
  2809. this.handleChangeJDateCommon(others[key], key + tempId, { id: tempId }, k, true)
  2810. } else {
  2811. this.popupJshValues[index][key] = others[key]
  2812. }
  2813. }
  2814. })
  2815. })
  2816. }
  2817. // 做单个表单验证
  2818. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2819. // 触发valueChange 事件
  2820. this.elemValueChange('input', row, column, value)
  2821. // 更新form表单的值
  2822. this.$nextTick(() => {
  2823. this.forceUpdateFormValues()
  2824. })
  2825. },
  2826. /** select输入框回显 */
  2827. getSelectValue(id) {
  2828. return this.selectValues[id]
  2829. },
  2830. /** popup输入框回显 */
  2831. getPopupValue(id) {
  2832. return this.popupValues[id]
  2833. },
  2834. /** popupJsh输入框回显 */
  2835. getPopupJshValue(id) {
  2836. return this.popupJshValues[id]
  2837. },
  2838. /** popupJsh构造传值 */
  2839. getPopupJshRows(row) {
  2840. let { values } = this.getValuesSync({ validate: false, rowIds: [row.id] })
  2841. return JSON.stringify(values[0])
  2842. },
  2843. handleRadioChange(value, id, row, column) {
  2844. this.radioValues = this.bindValuesChange(value, id, 'radioValues')
  2845. // 做单个表单验证
  2846. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2847. // 触发valueChange 事件
  2848. this.elemValueChange(FormTypes.radio, row, column, value)
  2849. },
  2850. handleMultiSelectChange(value, id, row, column) {
  2851. this.multiSelectValues = this.bindValuesChange(value, id, 'multiSelectValues')
  2852. // 做单个表单验证
  2853. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2854. // 触发valueChange 事件
  2855. this.elemValueChange(FormTypes.list_multi, row, column, value)
  2856. },
  2857. handleSearchSelectChange(value, id, row, column) {
  2858. this.searchSelectValues = this.bindValuesChange(value, id, 'searchSelectValues')
  2859. this.validateOneInput(value, row, column, this.notPassedIds, true, 'change')
  2860. this.elemValueChange(FormTypes.sel_search, row, column, value)
  2861. },
  2862. filterOption(input, option) {
  2863. return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  2864. },
  2865. getEllipsisWord(content, len) {
  2866. if (!content || content.length == 0) {
  2867. return ''
  2868. }
  2869. if (content.length > len) {
  2870. return content.substr(0, len)
  2871. }
  2872. return content
  2873. },
  2874. /** 回车后自动跳到下一个input **/
  2875. autoJumpNextInputBill() {
  2876. let that = this
  2877. let inputDom = $('.ant-modal-cust-warp:visible').find('#billModal')
  2878. inputDom
  2879. .find('input:visible:not(:checkbox)')
  2880. .off('keydown')
  2881. .on('keydown', function (e) {
  2882. //响应回车键按下的处理
  2883. e = event || window.event || arguments.callee.caller.arguments[0]
  2884. //捕捉是否按键为回车键,可百度JS键盘事件了解更多
  2885. if (e && e.keyCode == 13) {
  2886. //捕捉inputDom下的文本输入框的个数
  2887. let inputs = inputDom.find('input:visible:not(:checkbox)')
  2888. let idx = inputs.index(this) // 获取当前焦点输入框所处的位置
  2889. if (idx == inputs.length - 1) {
  2890. // 判断是否是最后一个输入框
  2891. let curKey = e.which
  2892. if (curKey == 13) {
  2893. //新增行
  2894. that.handleClickAdd()
  2895. //进行下一行的自动聚焦
  2896. setTimeout(function () {
  2897. inputs = inputDom.find('input:visible:not(:checkbox)')
  2898. inputs[idx + 1].focus() // 设置焦点
  2899. inputs[idx + 1].select() // 选中文字
  2900. }, 100)
  2901. }
  2902. } else {
  2903. inputs[idx + 1].focus() // 设置焦点
  2904. inputs[idx + 1].select() // 选中文字
  2905. }
  2906. }
  2907. })
  2908. },
  2909. /** 自动选中特殊的key **/
  2910. autoSelectBySpecialKey(specialKey, orderNum) {
  2911. let trs = this.getElement('tbody').getElementsByClassName('tr')
  2912. let trEls = []
  2913. if (trs && trs.length && orderNum >= 1) {
  2914. trEls.push(trs[orderNum - 1])
  2915. }
  2916. trEls.forEach((tr) => {
  2917. let { idx } = tr.dataset
  2918. let value = this.inputValues[idx]
  2919. for (let key in value) {
  2920. if (value.hasOwnProperty(key)) {
  2921. let elid = `${key}${value.id}`
  2922. let el = document.getElementById(elid)
  2923. if (el && key === specialKey) {
  2924. el.select()
  2925. }
  2926. }
  2927. }
  2928. })
  2929. },
  2930. },
  2931. beforeDestroy() {
  2932. this.destroyCleanGroupRequest = true
  2933. },
  2934. }
  2935. </script>
  2936. <style lang="less" scoped>
  2937. .action-button {
  2938. margin-bottom: 8px;
  2939. .gap {
  2940. padding-left: 8px;
  2941. }
  2942. }
  2943. /* 设定边框参数 */
  2944. @borderColor: #e8e8e8;
  2945. @border: 1px solid @borderColor;
  2946. /* tr & td 之间的间距 */
  2947. @spacing: 2px;
  2948. .input-table {
  2949. max-width: 100%;
  2950. overflow-x: hidden;
  2951. overflow-y: hidden;
  2952. position: relative;
  2953. border: @border;
  2954. .thead,
  2955. .tbody {
  2956. .tr,
  2957. .td {
  2958. display: flex;
  2959. }
  2960. .td {
  2961. /*border-right: 1px solid red;*/
  2962. /*color: white;*/
  2963. /*background-color: black;*/
  2964. /*margin-right: @spacing !important;*/
  2965. padding-left: @spacing;
  2966. flex-direction: column;
  2967. &.td-cb,
  2968. &.td-num {
  2969. min-width: 4%;
  2970. max-width: 45px;
  2971. margin-right: 0;
  2972. padding-left: 0;
  2973. padding-right: 0;
  2974. justify-content: center;
  2975. align-items: center;
  2976. }
  2977. &.td-ds {
  2978. margin-right: 0;
  2979. padding-left: 0;
  2980. padding-right: 0;
  2981. justify-content: center;
  2982. align-items: center;
  2983. .td-ds-icons {
  2984. position: relative;
  2985. cursor: move;
  2986. width: 100%;
  2987. /*padding: 25% 0;*/
  2988. height: 100%;
  2989. .anticon-align-left,
  2990. .anticon-align-right {
  2991. position: absolute;
  2992. top: 30%;
  2993. }
  2994. .anticon-align-left {
  2995. left: 25%;
  2996. }
  2997. .anticon-align-right {
  2998. right: 25%;
  2999. }
  3000. }
  3001. }
  3002. }
  3003. }
  3004. .thead {
  3005. overflow-y: scroll;
  3006. overflow-x: hidden;
  3007. border-bottom: @border;
  3008. /** 隐藏thead的滑块 */
  3009. &::-webkit-scrollbar-thumb {
  3010. box-shadow: none !important;
  3011. background-color: transparent !important;
  3012. }
  3013. .tr {
  3014. min-width: 100%;
  3015. overflow-y: scroll;
  3016. }
  3017. .td {
  3018. /*flex: 1;*/
  3019. padding: 8px @spacing;
  3020. justify-content: center;
  3021. }
  3022. }
  3023. .tbody {
  3024. position: relative;
  3025. top: 0;
  3026. left: 0;
  3027. overflow-x: hidden;
  3028. overflow-y: hidden;
  3029. min-height: 61px;
  3030. /*max-height: 400px;*/
  3031. min-width: 100%;
  3032. .tr-nodata {
  3033. color: #999;
  3034. line-height: 61px;
  3035. text-align: center;
  3036. }
  3037. .tr {
  3038. /*line-height: 50px;*/
  3039. border-bottom: @border;
  3040. transition: background-color 300ms;
  3041. width: 100%;
  3042. position: absolute;
  3043. left: 0;
  3044. z-index: 10;
  3045. &.tr-checked {
  3046. background-color: #fafafa;
  3047. }
  3048. &:hover {
  3049. background-color: #e6f7ff;
  3050. }
  3051. }
  3052. .tr-expand {
  3053. position: relative;
  3054. z-index: 9;
  3055. background-color: white;
  3056. }
  3057. .td {
  3058. /*flex: 1;*/
  3059. padding: 6px @spacing 6px 0;
  3060. justify-content: center;
  3061. &:last-child {
  3062. padding-right: @spacing;
  3063. }
  3064. input {
  3065. font-variant: tabular-nums;
  3066. box-sizing: border-box;
  3067. margin: 0;
  3068. list-style: none;
  3069. position: relative;
  3070. display: inline-block;
  3071. padding: 2px 2px;
  3072. width: 100%;
  3073. height: 32px;
  3074. font-size: 14px;
  3075. line-height: 1.5;
  3076. color: rgba(0, 0, 0, 0.65);
  3077. background-color: #fff;
  3078. border: 1px solid #d9d9d9;
  3079. border-radius: 4px;
  3080. transition: all 0.3s;
  3081. outline: none;
  3082. &:hover {
  3083. border-color: #4d90fe;
  3084. }
  3085. &:focus {
  3086. border-color: #40a9ff;
  3087. box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
  3088. border-right-width: 1px !important;
  3089. }
  3090. &:disabled {
  3091. color: rgba(0, 0, 0, 0.25);
  3092. background: #f5f5f5;
  3093. cursor: not-allowed;
  3094. }
  3095. /* 设置placeholder的颜色 */
  3096. &::-webkit-input-placeholder {
  3097. /* WebKit browsers */
  3098. color: #ccc;
  3099. }
  3100. &:-moz-placeholder {
  3101. /* Mozilla Firefox 4 to 18 */
  3102. color: #ccc;
  3103. }
  3104. &::-moz-placeholder {
  3105. /* Mozilla Firefox 19+ */
  3106. color: #ccc;
  3107. }
  3108. &:-ms-input-placeholder {
  3109. /* Internet Explorer 10+ */
  3110. color: #ccc;
  3111. }
  3112. }
  3113. .j-editable-image {
  3114. height: 32px;
  3115. max-width: 100px !important;
  3116. cursor: pointer;
  3117. &:hover {
  3118. opacity: 0.8;
  3119. }
  3120. &:active {
  3121. opacity: 0.6;
  3122. }
  3123. }
  3124. .td-span {
  3125. font-variant: tabular-nums;
  3126. box-sizing: border-box;
  3127. margin: 0;
  3128. list-style: none;
  3129. position: relative;
  3130. display: inline-block;
  3131. padding: 2px 2px;
  3132. width: 100%;
  3133. height: 32px;
  3134. font-size: 14px;
  3135. line-height: 1.9;
  3136. color: rgba(0, 0, 0, 0.65);
  3137. background-color: #fff;
  3138. border: 1px dashed #d9d9d9;
  3139. border-radius: 4px;
  3140. transition: all 0.3s;
  3141. outline: none;
  3142. overflow: hidden;
  3143. white-space: nowrap;
  3144. text-overflow: ellipsis;
  3145. }
  3146. }
  3147. }
  3148. .scroll-view {
  3149. overflow: auto;
  3150. overflow-y: scroll;
  3151. }
  3152. .thead,
  3153. .thead .tr,
  3154. .scroll-view {
  3155. @scrollBarSize: 6px;
  3156. /* 定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
  3157. &::-webkit-scrollbar {
  3158. width: @scrollBarSize;
  3159. height: @scrollBarSize;
  3160. background-color: transparent;
  3161. }
  3162. /* 定义滚动条轨道 */
  3163. &::-webkit-scrollbar-track {
  3164. background-color: #f0f0f0;
  3165. }
  3166. /* 定义滑块 */
  3167. &::-webkit-scrollbar-thumb {
  3168. background-color: #eee;
  3169. box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
  3170. &:hover {
  3171. background-color: #bbb;
  3172. }
  3173. &:active {
  3174. background-color: #888;
  3175. }
  3176. }
  3177. }
  3178. .thead .tr {
  3179. &::-webkit-scrollbar-track {
  3180. background-color: transparent;
  3181. }
  3182. /* IE模式下隐藏 */
  3183. -ms-overflow-style: none;
  3184. -ms-scroll-chaining: chained;
  3185. -ms-content-zooming: zoom;
  3186. -ms-scroll-rails: none;
  3187. -ms-content-zoom-limit-min: 100%;
  3188. -ms-content-zoom-limit-max: 500%;
  3189. -ms-scroll-snap-type: proximity;
  3190. -ms-scroll-snap-points-x: snapList(100%, 200%, 300%, 400%, 500%);
  3191. }
  3192. }
  3193. </style>