9d8b0d53b879dda13d91503838ef17ddcac0cdac.svn-base 122 KB

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