license_info 9.11.html 137 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>License 分发管理</title>
  7. <style>
  8. /* 保持样式不变 */
  9. body {
  10. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  11. background-color: #f8f8f8;
  12. margin: 0;
  13. padding: 0;
  14. display: flex;
  15. }
  16. header {
  17. display: flex;
  18. justify-content: space-between;
  19. align-items: center;
  20. padding: 20px;
  21. background-color: #1169ff;
  22. color: white;
  23. width: 100%;
  24. margin: 0; /* 移除上下左右的空隙 */
  25. box-sizing: border-box; /* 确保padding不会影响元素的宽度 */
  26. border: 4px solid #1169ff; /* 确保红框颜色填满 */
  27. border-width: 4px 0 4px 0; /* 只显示上下的红框颜色 */
  28. border-radius: 10px; /* 设置圆角 */
  29. }
  30. h1 {
  31. font-size: 24px;
  32. font-weight: 600;
  33. margin: 0;
  34. }
  35. .CaptureLicenseOnce-button {
  36. background-color: white;
  37. color: #007aff;
  38. border: 2px solid #007aff;
  39. padding: 10px 20px;
  40. border-radius: 10px;
  41. cursor: pointer;
  42. font-size: 16px;
  43. font-weight: 500;
  44. box-shadow: none;
  45. transition: background-color 0.3s, color 0.3s;
  46. float: right; /* 将按钮移动到左侧 */
  47. }
  48. .CaptureLicenseOnce-button:hover {
  49. background-color: #0eb3ff;
  50. color: white;
  51. }
  52. /* 扁平风格的选择框 */
  53. .flat-select {
  54. background-color: transparent; /* 背景色透明 */
  55. border: 1px solid #007aff; /* 边框颜色与按钮一致 */
  56. border-radius: 15px; /* 圆角边框 */
  57. padding: 5px 10px; /* 内边距 */
  58. font-size: 16px; /* 字体大小 */
  59. color: #007aff; /* 文字颜色 */
  60. outline: none; /* 移除默认的焦点样式 */
  61. appearance: none; /* 移除默认的下拉箭头样式 */
  62. -webkit-appearance: none; /* 对部分浏览器的兼容性处理 */
  63. -moz-appearance: none; /* 对部分浏览器的兼容性处理 */
  64. cursor: pointer; /* 鼠标指针样式 */
  65. margin-left: 10px; /* 添加左边距,使选择框与前面的元素有些距离 */
  66. box-shadow: none; /* 移除阴影效果 */
  67. transition: background-color 0.3s, color 0.3s; /* 添加过渡效果 */
  68. }
  69. /* 选择框在悬停时的效果 */
  70. .flat-select:hover {
  71. background-color: #007aff; /* 背景色变为蓝色 */
  72. color: white; /* 文字颜色变为白色 */
  73. }
  74. /* 选择框在聚焦时的效果 */
  75. .flat-select:focus {
  76. background-color: #e0f7ff; /* 聚焦时的背景颜色 */
  77. border-color: #0056b3; /* 聚焦时的边框颜色 */
  78. }
  79. /* 添加下拉箭头的样式 */
  80. .flat-select::after {
  81. content: '▼'; /* 使用字符作为下拉箭头 */
  82. position: absolute;
  83. right: 10px;
  84. pointer-events: none; /* 确保下拉箭头不会遮挡选择框 */
  85. }
  86. /* 扁平圆角风格的按钮样式 */
  87. .flat-rounded-button {
  88. background-color: white;
  89. color: #007aff;
  90. border: 2px solid #007aff;
  91. padding: 10px 20px;
  92. border-radius: 15px;
  93. cursor: pointer;
  94. font-size: 16px;
  95. font-weight: 500;
  96. box-shadow: none; /* 移除阴影效果 */
  97. transition: background-color 0.3s, color 0.3s;
  98. margin: 5px; /* 添加按钮之间的间距 */
  99. }
  100. /* 悬停时的效果 */
  101. .flat-rounded-button:hover {
  102. background-color: #0eb3ff;
  103. color: white;
  104. }
  105. /*lic 展示页 主行展开后变化*/
  106. .expanded-row {
  107. background-color: #0eb3ff; /* 展开时的背景颜色 */
  108. border-color: #04aa9c; /* 展开时的边框颜色 */
  109. border-width: 4px; /* 边框宽度 */
  110. border-radius: 35px; /* 边框圆角 */
  111. transition: all 0.2s ease; /* 添加过渡效果 */
  112. }
  113. /*苹果风格模态框*/
  114. .apple-modal-content {
  115. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  116. padding: 20px;
  117. border-radius: 12px;
  118. background-color: white;
  119. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  120. margin-bottom: 20px;
  121. min-width: 250px; /* 添加最小宽度 */
  122. }
  123. .apple-modal-title {
  124. font-size: 24px;
  125. font-weight: 600;
  126. color: #333;
  127. margin-bottom: 10px;
  128. }
  129. .apple-modal-subtitle {
  130. font-size: 20px;
  131. font-weight: 500;
  132. color: #555;
  133. margin-top: 20px;
  134. margin-bottom: 10px;
  135. }
  136. /* 苹果风格的文字样式 */
  137. .apple-modal-text {
  138. font-size: 16px;
  139. color: #555;
  140. line-height: 1.6;
  141. margin-bottom: 10px;
  142. }
  143. /* 强调部分 */
  144. .apple-modal-text strong {
  145. color: #333;
  146. }
  147. /* 苹果风格的模态框关闭按钮 */
  148. .apple-close {
  149. color: #aaa;
  150. font-size: 24px; /* 调整字体大小 */
  151. font-weight: bold;
  152. cursor: pointer;
  153. transition: color 0.3s;
  154. }
  155. .apple-close:hover {
  156. color: black;
  157. }
  158. /* 苹果风格的退出按钮 */
  159. .apple-logout-button {
  160. background-color: #007aff; /* 苹果风格的蓝色 */
  161. color: white;
  162. border: none;
  163. padding: 8px 16px; /* 减小内边距,使按钮更小 */
  164. border-radius: 10px; /* 圆角稍微减小 */
  165. font-size: 14px; /* 调整字体大小 */
  166. font-weight: 500;
  167. cursor: pointer;
  168. transition: background-color 0.3s, transform 0.3s;
  169. }
  170. .apple-logout-button:hover {
  171. background-color: #005bb5; /* 悬停时按钮颜色变深 */
  172. transform: scale(1.05); /* 悬停时按钮略微放大 */
  173. }
  174. .apple-logout-button:active {
  175. background-color: #003e7e; /* 点击时按钮颜色更深 */
  176. transform: scale(0.98); /* 点击时按钮略微缩小 */
  177. }
  178. .upload-button, .user-button {
  179. background-color: white;
  180. color: #007aff;
  181. border: none;
  182. padding: 10px 20px;
  183. border-radius: 10px;
  184. cursor: pointer;
  185. font-size: 16px;
  186. font-weight: 500;
  187. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  188. transition: background-color 0.3s;
  189. }
  190. .upload-button:hover, .user-button:hover {
  191. background-color: #f0f0f0;
  192. }
  193. .sidebar {
  194. width: 200px;
  195. background-color: #f1f1f1;
  196. padding: 20px;
  197. box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
  198. height: 100vh;
  199. transition: transform 0.3s ease;
  200. }
  201. .sidebar.hidden {
  202. transform: translateX(-100%);
  203. }
  204. .sidebar button {
  205. width: 100%;
  206. padding: 10px;
  207. margin-bottom: 10px;
  208. background-color: white;
  209. color: #007aff;
  210. border: none;
  211. border-radius: 10px;
  212. cursor: pointer;
  213. font-size: 16px;
  214. font-weight: 500;
  215. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  216. transition: background-color 0.3s;
  217. }
  218. .sidebar button:hover {
  219. background-color: #e0e0e0;
  220. }
  221. .content {
  222. flex-grow: 1;
  223. padding: 20px;
  224. transition: margin-left 0.3s ease;
  225. }
  226. .content.expanded {
  227. margin-left: -200px;
  228. }
  229. .toggle-sidebar {
  230. position: fixed;
  231. top: 50%; /* 垂直居中 */
  232. transform: translateY(-50%); /* 调整为居中对齐 */
  233. left: 0; /* 靠左对齐 */
  234. background-color: #007aff;
  235. color: white;
  236. border: none;
  237. padding: 10px;
  238. cursor: pointer;
  239. border-radius: 0 10px 10px 0; /* 右侧圆角,左侧保持平直 */
  240. width: 30px; /* 长条形箭头的宽度 */
  241. height: 60px; /* 长条形箭头的高度 */
  242. z-index: 1000;
  243. display: flex;
  244. align-items: center;
  245. justify-content: center;
  246. transition: all 0.3s ease; /* 添加动效 */
  247. }
  248. .sidebar.hidden + .content .toggle-sidebar {
  249. left: 0;
  250. transform: translateX(0) translateY(-50%);
  251. }
  252. /* 按钮容器的样式 */
  253. .button-container {
  254. display: inline-flex; /* 确保按钮在同一行 */
  255. align-items: center; /* 垂直居中对齐 */
  256. gap: 10px; /* 设置按钮之间的间距为10px,可以根据需要调整 */
  257. }
  258. /* 统一按钮的样式 */
  259. /* 通用按钮样式 */
  260. .license-status-btn {
  261. display: inline-block;
  262. padding: 5px 15px;
  263. font-size: 14px;
  264. font-weight: bold;
  265. color: white;
  266. text-align: center;
  267. border-radius: 15px; /* 圆角样式 */
  268. cursor: pointer;
  269. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 阴影效果 */
  270. transition: background-color 0.3s;
  271. border: none; /* 移除按钮边框 */
  272. }
  273. /* 查看详情按钮的特定样式 */
  274. .license-status-btn.view-details {
  275. background-color: #add8e6; /* 浅蓝色背景 */
  276. color: white;
  277. }
  278. /* 下载lic按钮的特定样式 */
  279. .license-status-btn.download-lic {
  280. background-color: #4CAF50; /* 绿色背景 */
  281. color: white;
  282. }
  283. /* 分发按钮样式 */
  284. .license-status-btn.distribute {
  285. background-color: #007bff; /* 蓝色背景 */
  286. }
  287. .license-status-btn.distribute:hover {
  288. background-color: #0056b3; /* 悬停时的颜色 */
  289. }
  290. /* 生成按钮样式 */
  291. .license-status-btn.generate {
  292. background-color: #ffc107; /* 黄色背景 */
  293. }
  294. .license-status-btn.generate:hover {
  295. background-color: #e0a800; /* 悬停时的颜色 */
  296. }
  297. /* 默认状态下的箭头图标 */
  298. .arrow-icon {
  299. width: 10px;
  300. height: 10px;
  301. border: solid #007aff;
  302. border-width: 0 3px 3px 0;
  303. display: inline-block;
  304. padding: 3px;
  305. transform: rotate(45deg); /* 初始方向向下 */
  306. transition: transform 0.3s ease; /* 添加旋转过渡效果 */
  307. cursor: pointer;
  308. }
  309. /* 当行展开时旋转箭头图标 */
  310. .rotate-arrow {
  311. transform: rotate(-135deg); /* 旋转方向向上 */
  312. }
  313. /*分发历史样式*/
  314. #distributionHistoryModal .centered-modal-content {
  315. background-color: #ffffff;
  316. border: none;
  317. border-radius: 15px;
  318. padding: 20px;
  319. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  320. text-align: center;
  321. width: 30%; /* 设置宽度为屏幕的80% */
  322. max-width: 90%; /* 最大宽度设置为90%屏幕宽度 */
  323. height: auto; /* 高度自适应内容 */
  324. max-height: 80vh; /* 设置最大高度为屏幕的80% */
  325. overflow-y: auto; /* 如果内容超出则添加垂直滚动条 */
  326. overflow-x: hidden; /* 水平不出现滚动条 */
  327. margin: 0 auto; /* 居中显示 */
  328. }
  329. /* lic查看详细按钮样式 */
  330. .license-status-btn.view-details {
  331. background-color: #add8e6; /* 浅蓝色背景 */
  332. color: white; /* 白色文字 */
  333. border: none; /* 移除按钮边框 */
  334. padding: 8px 16px; /* 调整内边距,与“生成”按钮保持一致 */
  335. border-radius: 20px; /* 调整圆角,确保形状一致 */
  336. cursor: pointer;
  337. font-size: 14px; /* 调整字体大小,确保一致 */
  338. font-weight: 500; /* 字体权重,确保一致 */
  339. margin-left: 10px; /* 与其他按钮的间隔 */
  340. transition: background-color 0.3s, color 0.3s; /* 添加过渡效果 */
  341. }
  342. .license-status-btn.view-details:hover {
  343. background-color: #87ceeb; /* 悬停时颜色变深 */
  344. }
  345. /* 表格样式 */
  346. /* 表格容器 */
  347. /* 表格容器 */
  348. table {
  349. width: 100%;
  350. border-collapse: separate;
  351. border-spacing: 0 4px; /* 设置行间距为4px */
  352. /* background-color: transparent; 使表格背景透明,突出行间距效果 */
  353. margin: 20px 0;
  354. }
  355. th, td {
  356. padding: 15px 20px; /* 设置单元格内边距 */
  357. text-align: left;
  358. font-size: 16px;
  359. /* background-color: white; 单元格背景色 */
  360. }
  361. /* 鼠标悬停时改变边框颜色 */
  362. tr:hover {
  363. background-color: #e6f7ff; /* 设置悬停时的背景颜色 */
  364. border-color: #1169ff; /* 设置悬停时的边框颜色 */
  365. border-width: 4px; /* 设置悬停时的边框大小 */
  366. border-radius: 15px; /* 设置悬停时的圆角 */
  367. }
  368. th {
  369. background-color: #f8f8f8; /* 表头背景色 */
  370. font-weight: bold;
  371. color: #333;
  372. }
  373. td {
  374. color: #555;
  375. }
  376. /* 表格行样式 */
  377. tr {
  378. background-color: white; /* 每行背景色 */
  379. box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1); /* 设置阴影效果 */
  380. border-radius: 10px; /* 设置每行的圆角 */
  381. overflow: hidden; /* 确保圆角效果生效 */
  382. border: 2px solid transparent; /* 默认边框为透明 */
  383. transition: all 0.3s ease; /* 添加过渡效果 */
  384. }
  385. /* 确保单元格也适应行的圆角 */
  386. tr:first-child td:first-child {
  387. border-top-left-radius: 10px;
  388. }
  389. tr:first-child td:last-child {
  390. border-top-right-radius: 10px;
  391. }
  392. tr:last-child td:first-child {
  393. border-bottom-left-radius: 10px;
  394. }
  395. tr:last-child td:last-child {
  396. border-bottom-right-radius: 10px;
  397. }
  398. /*添加用户样式*/
  399. .flat-rounded-input {
  400. width: calc(100% - 40px); /* 与其他输入框一致的宽度 */
  401. padding: 15px 20px; /* 更大的内边距 */
  402. font-size: 18px; /* 更大的字体 */
  403. border: 2px solid #e0e0e0; /* 边框颜色 */
  404. border-radius: 25px; /* 圆角边框 */
  405. box-sizing: border-box;
  406. margin-bottom: 20px;
  407. background-color: #f8f8f8; /* 背景色 */
  408. transition: border-color 0.3s, box-shadow 0.3s; /* 添加动画效果 */
  409. }
  410. .flat-rounded-input:focus {
  411. border-color: #007aff; /* 聚焦时的边框颜色 */
  412. box-shadow: 0 0 8px rgba(0, 122, 255, 0.2); /* 聚焦时的阴影效果 */
  413. outline: none; /* 去掉默认的聚焦样式 */
  414. }
  415. .flat-rounded-button {
  416. background-color: #007aff;
  417. color: white;
  418. border: none;
  419. padding: 15px 20px;
  420. border-radius: 25px;
  421. cursor: pointer;
  422. font-size: 18px;
  423. font-weight: bold;
  424. box-shadow: none; /* 移除阴影效果 */
  425. transition: background-color 0.3s, color 0.3s;
  426. }
  427. .flat-rounded-button:hover {
  428. background-color: #005bb5;
  429. }
  430. .form-group {
  431. display: flex;
  432. align-items: center;
  433. margin-bottom: 15px;
  434. }
  435. .form-group label {
  436. flex: 0 0 80px; /* 固定标签宽度 */
  437. text-align: right;
  438. margin-right: 10px; /* 标签与输入框之间的间距 */
  439. }
  440. .form-group input {
  441. flex: 1; /* 输入框占据剩余空间 */
  442. }
  443. /* 分页按钮样式 */
  444. .pagination button {
  445. padding: 10px 20px;
  446. margin: 0 5px;
  447. cursor: pointer;
  448. border: none;
  449. border-radius: 15px;
  450. background-color: #007aff;
  451. color: white;
  452. font-size: 16px;
  453. font-weight: 500;
  454. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  455. transition: background-color 0.3s;
  456. }
  457. .pagination button:disabled {
  458. background-color: #b0c4de;
  459. cursor: not-allowed;
  460. }
  461. .pagination button:not(:disabled):hover {
  462. background-color: #005bb5;
  463. }
  464. .modal {
  465. display: none;
  466. position: fixed;
  467. z-index: 1;
  468. left: 0;
  469. top: 0;
  470. width: 100%;
  471. height: 100%;
  472. overflow: auto;
  473. background-color: rgba(0, 0, 0, 0.4);
  474. }
  475. .modal-content {
  476. position: fixed;
  477. top: 50%;
  478. left: 50%;
  479. transform: translate(-50%, -50%);
  480. background-color: #fefefe;
  481. padding: 20px;
  482. border: 1px solid #888;
  483. border-radius: 10px;
  484. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  485. max-width: 100%;
  486. max-height: 90%;
  487. overflow-y: auto;
  488. }
  489. /*修改license信息的样式*/
  490. .modify-license-modal-content {
  491. position: fixed;
  492. top: 50%;
  493. left: 50%;
  494. transform: translate(-50%, -50%);
  495. background-color: #fefefe;
  496. padding: 50px;
  497. border: 1px solid #888;
  498. border-radius: 10px;
  499. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  500. width: 400px;
  501. height: 80%; /* 设置为你希望的高度 */
  502. overflow-y: auto;
  503. text-align: center;
  504. }
  505. .modify-license-modal-content input[type="number"],
  506. .modify-license-modal-content input[type="date"],
  507. .modify-license-modal-content input[type="text"],
  508. .modify-license-modal-content input[type="email"],
  509. .modify-license-modal-content input[type="password"],
  510. .modify-license-modal-content textarea,
  511. .modify-license-modal-content select {
  512. width: calc(100% - 40px);
  513. padding: 15px 20px; /* 更大内边距 */
  514. font-size: 18px; /* 更大字体 */
  515. border: 2px solid #e0e0e0; /* 边框颜色 */
  516. border-radius: 25px; /* 圆形边框 */
  517. box-sizing: border-box;
  518. margin-bottom: 20px;
  519. background-color: #f8f8f8; /* 背景色更浅 */
  520. transition: border-color 0.3s, box-shadow 0.3s; /* 添加动画效果 */
  521. }
  522. .modify-license-modal-content input[type="number"]:focus,
  523. .modify-license-modal-content input[type="date"]:focus,
  524. .modify-license-modal-content input[type="text"]:focus,
  525. .modify-license-modal-content input[type="email"]:focus,
  526. .modify-license-modal-content input[type="password"]:focus,
  527. .modify-license-modal-content textarea:focus,
  528. .modify-license-modal-content select:focus {
  529. border-color: #007aff; /* 聚焦时的边框颜色 */
  530. box-shadow: 0 0 8px rgba(0, 122, 255, 0.2); /* 聚焦时的阴影效果 */
  531. outline: none; /* 去掉默认的聚焦样式 */
  532. }
  533. .modify-license-modal-content button {
  534. width: 100%;
  535. padding: 15px 20px;
  536. font-size: 18px;
  537. font-weight: bold;
  538. color: white;
  539. background-color: #007aff;
  540. border: none;
  541. border-radius: 25px;
  542. cursor: pointer;
  543. transition: background-color 0.3s;
  544. }
  545. .modify-license-modal-content button:hover {
  546. background-color: #005bb5; /* 鼠标悬停时的颜色变化 */
  547. }
  548. .modify-license-modal-content .close {
  549. color: #aaa;
  550. float: right;
  551. font-size: 30px;
  552. font-weight: bold;
  553. }
  554. .modify-license-modal-content .close:hover,
  555. .modify-license-modal-content .close:focus {
  556. color: black;
  557. text-decoration: none;
  558. cursor: pointer;
  559. }
  560. .modify-license-modal-content .extra-info {
  561. padding: 20px;
  562. background-color: white;
  563. border: 1px solid #ddd;
  564. border-radius: 10px;
  565. margin-top: 10px;
  566. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  567. line-height: 1.5; /* 增加行高,保证字段间距 */
  568. }
  569. .modal-content input[type="number"] {
  570. width: calc(100% - 40px);
  571. padding: 15px 20px; /* 与其他输入框的内边距一致 */
  572. font-size: 18px; /* 与其他输入框的字体大小一致 */
  573. border: 2px solid #e0e0e0; /* 与其他输入框的边框颜色一致 */
  574. border-radius: 25px; /* 与其他输入框的圆角一致 */
  575. box-sizing: border-box;
  576. margin-bottom: 20px;
  577. background-color: #f8f8f8; /* 与其他输入框的背景色一致 */
  578. transition: border-color 0.3s, box-shadow 0.3s; /* 与其他输入框的过渡效果一致 */
  579. }
  580. .modal-content input[type="number"]:focus {
  581. border-color: #007aff; /* 与其他输入框获得焦点时的边框颜色一致 */
  582. box-shadow: 0 0 8px rgba(0, 122, 255, 0.2); /* 与其他输入框获得焦点时的阴影效果一致 */
  583. outline: none; /* 移除默认的焦点轮廓 */
  584. }
  585. .modal-content input[type="date"] {
  586. width: calc(100% - 40px);
  587. padding: 15px 20px; /* 与其他输入框的内边距一致 */
  588. font-size: 18px; /* 与其他输入框的字体大小一致 */
  589. border: 2px solid #e0e0e0; /* 与其他输入框的边框颜色一致 */
  590. border-radius: 25px; /* 与其他输入框的圆角一致 */
  591. box-sizing: border-box;
  592. margin-bottom: 20px;
  593. background-color: #f8f8f8; /* 与其他输入框的背景色一致 */
  594. transition: border-color 0.3s, box-shadow 0.3s; /* 与其他输入框的过渡效果一致 */
  595. }
  596. .modal-content input[type="date"]:focus {
  597. border-color: #007aff; /* 与其他输入框获得焦点时的边框颜色一致 */
  598. box-shadow: 0 0 8px rgba(0, 122, 255, 0.2); /* 与其他输入框获得焦点时的阴影效果一致 */
  599. outline: none; /* 移除默认的焦点轮廓 */
  600. }
  601. /* 输入框样式 */
  602. .modal-content input[type="text"],
  603. .modal-content input[type="email"],
  604. .modal-content input[type="password"],
  605. .modal-content textarea,
  606. .modal-content select {
  607. width: calc(100% - 40px);
  608. padding: 15px 20px; /* 更大内边距 */
  609. font-size: 18px; /* 更大字体 */
  610. border: 2px solid #e0e0e0; /* 边框颜色 */
  611. border-radius: 25px; /* 圆形边框 */
  612. box-sizing: border-box;
  613. margin-bottom: 20px;
  614. background-color: #f8f8f8; /* 背景色更浅 */
  615. transition: border-color 0.3s, box-shadow 0.3s; /* 添加动画效果 */
  616. }
  617. /* 输入框聚焦时的样式 */
  618. .modal-content input[type="text"]:focus,
  619. .modal-content input[type="email"]:focus,
  620. .modal-content input[type="password"]:focus,
  621. .modal-content textarea:focus,
  622. .modal-content select:focus {
  623. border-color: #007aff; /* 聚焦时的边框颜色 */
  624. box-shadow: 0 0 8px rgba(0, 122, 255, 0.2); /* 聚焦时的阴影效果 */
  625. outline: none; /* 去掉默认的聚焦样式 */
  626. }
  627. /* 按钮样式 */
  628. .modal-content button {
  629. width: 100%;
  630. padding: 15px 20px;
  631. font-size: 18px;
  632. font-weight: bold;
  633. color: white;
  634. background-color: #007aff;
  635. border: none;
  636. border-radius: 25px;
  637. cursor: pointer;
  638. transition: background-color 0.3s;
  639. }
  640. .modal-content button:hover {
  641. background-color: #005bb5; /* 鼠标悬停时的颜色变化 */
  642. }
  643. .close {
  644. color: #aaa;
  645. float: right;
  646. font-size: 30px;
  647. font-weight: bold;
  648. text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
  649. }
  650. .close:hover {
  651. color: #000; /* 悬停时颜色变为黑色 */
  652. transform: scale(1.1); /* 悬停时稍微放大 */
  653. }
  654. .close:focus {
  655. color: black;
  656. text-decoration: none;
  657. cursor: pointer;
  658. }
  659. .extra-info {
  660. padding: 20px;
  661. background-color: white;
  662. border: 1px solid #ddd;
  663. border-radius: 10px;
  664. margin-top: 10px;
  665. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  666. line-height: 1.5; /* 增加行高,保证字段间距 */
  667. }
  668. .extra-info p {
  669. margin: 10px 0; /* 每个字段的间距 */
  670. word-wrap: break-word; /* 允许在单词内断行 */
  671. word-break: break-all; /* 允许在任何字符处断行 */
  672. white-space: pre-wrap; /* 保持空格和换行符 */
  673. border-bottom: 1px solid #f0f0f0; /* 每个字段下方加上细线 */
  674. padding-bottom: 8px; /* 加大下方内边距 */
  675. }
  676. /* 修改运维邮箱和销售邮箱的勾选框样式 */
  677. #emailInputs {
  678. display: flex;
  679. flex-direction: column; /* 确保每一行都垂直排列 */
  680. gap: 10px; /* 增加每行之间的间距 */
  681. }
  682. #emailInputs div {
  683. display: flex;
  684. align-items: center; /* 垂直居中 */
  685. }
  686. #emailInputs input[type="checkbox"] {
  687. appearance: none;
  688. background-color: #fff;
  689. margin: 0;
  690. font: inherit;
  691. color: #007aff;
  692. width: 1.15em;
  693. height: 1.15em;
  694. border: 0.15em solid #007aff;
  695. border-radius: 0.15em;
  696. transform: translateY(-0.075em);
  697. display: grid;
  698. place-content: center;
  699. }
  700. #emailInputs input[type="checkbox"]::before {
  701. content: "";
  702. width: 0.65em;
  703. height: 0.65em;
  704. clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 22%, 80% 0%, 43% 62%);
  705. transform: scale(0);
  706. transform-origin: bottom left;
  707. transition: transform 0.15s ease-in-out;
  708. box-shadow: inset 1em 1em #007aff;
  709. /* 使用淡蓝色与主题颜色匹配 */
  710. background-color: CanvasText;
  711. }
  712. #emailInputs input[type="checkbox"]:checked::before {
  713. transform: scale(1);
  714. }
  715. .user-info {
  716. position: absolute;
  717. width: 300px;
  718. background-color: white;
  719. padding: 20px;
  720. border: 1px solid #ddd;
  721. border-radius: 10px;
  722. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  723. display: none;
  724. }
  725. .user-info .close {
  726. position: absolute;
  727. top: 10px;
  728. right: 10px;
  729. color: #aaa;
  730. font-size: 24px;
  731. font-weight: bold;
  732. cursor: pointer;
  733. }
  734. .user-info .close:hover,
  735. .user-info .close:focus {
  736. color: black;
  737. text-decoration: none;
  738. }
  739. .centered-modal-content {
  740. position: fixed;
  741. top: 50%;
  742. left: 50%;
  743. transform: translate(-50%, -50%);
  744. background-color: #fefefe;
  745. padding: 50px;
  746. border: 1px solid #888;
  747. border-radius: 10px;
  748. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  749. width: 400px;
  750. height: 400px;
  751. overflow-y: auto;
  752. text-align: center;
  753. }
  754. .ios-button {
  755. width: 100%;
  756. padding: 10px;
  757. margin: 0;
  758. border: none;
  759. border-radius: 0;
  760. font-size: 16px;
  761. font-weight: 600;
  762. color: #007aff;
  763. background-color: transparent;
  764. text-align: center;
  765. cursor: pointer;
  766. transition: background-color 0.3s;
  767. }
  768. .ios-button:active {
  769. background-color: rgba(0, 122, 255, 0.1);
  770. }
  771. .email-modal-label {
  772. font-size: 18px;
  773. margin-bottom: 10px;
  774. display: block;
  775. }
  776. .email-modal-input {
  777. width: calc(100% - 20px);
  778. padding: 10px;
  779. font-size: 16px;
  780. border: 1px solid #ccc;
  781. border-radius: 5px;
  782. margin-bottom: 10px;
  783. }
  784. .email-modal .modal-content {
  785. width: 90%; /* 修改宽度 */
  786. max-width: 600px; /* 最大宽度 */
  787. height: auto; /* 自适应高度 */
  788. max-height: 80%; /* 最大高度,防止内容溢出屏幕 */
  789. overflow-y: auto; /* 添加垂直滚动条,如果内容超出 */
  790. }
  791. .add-email-button {
  792. display: block;
  793. width: 100%;
  794. padding: 10px 20px;
  795. margin-bottom: 10px;
  796. background-color: #007aff;
  797. color: white;
  798. border: none;
  799. text-align: center;
  800. font-size: 16px;
  801. cursor: pointer;
  802. border-radius: 5px;
  803. transition: background-color 0.3s;
  804. }
  805. .add-email-button:hover {
  806. background-color: #005bb5;
  807. }
  808. .action-modal-content {
  809. display: flex;
  810. flex-direction: column;
  811. align-items: flex-start;
  812. }
  813. .action-modal-content button {
  814. width: auto;
  815. padding: 10px 20px;
  816. margin: 5px 0;
  817. background-color: white;
  818. color: black;
  819. border: none;
  820. text-align: left;
  821. font-size: 16px;
  822. cursor: pointer;
  823. border-radius: 5px;
  824. transition: background-color 0.3s;
  825. }
  826. .action-modal-content button:hover {
  827. background-color: #f0f0f0;
  828. }
  829. .sort-button {
  830. background-color: transparent;
  831. border: none;
  832. color: #007aff;
  833. font-size: 16px;
  834. cursor: pointer;
  835. padding: 5px 10px;
  836. border-radius: 15px;
  837. transition: background-color 0.3s;
  838. }
  839. .sort-button:hover {
  840. background-color: rgba(0, 122, 255, 0.1);
  841. }
  842. #confirmGenerateModal .centered-modal-content {
  843. background-color: #ffffff;
  844. border: none;
  845. border-radius: 15px;
  846. padding: 20px;
  847. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  848. text-align: center;
  849. }
  850. #confirmGenerateModal .centered-modal-content button {
  851. background-color: #007aff;
  852. color: white;
  853. border: none;
  854. border-radius: 10px;
  855. padding: 10px 20px;
  856. cursor: pointer;
  857. font-size: 16px;
  858. margin: 10px;
  859. transition: all 0.3s;
  860. }
  861. #confirmGenerateModal .centered-modal-content button:hover {
  862. background-color: #005bb5;
  863. border: 1px solid #007aff;
  864. }
  865. #role-management {
  866. padding: 20px;
  867. background-color: white;
  868. border-radius: 10px;
  869. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  870. }
  871. /* 角色项的默认样式 */
  872. .role-item {
  873. background-color: white; /* 默认背景色 */
  874. box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1); /* 阴影效果 */
  875. border-radius: 10px; /* 圆角效果 */
  876. overflow: hidden; /* 确保圆角效果生效 */
  877. border: 2px solid transparent; /* 默认边框为透明 */
  878. transition: all 0.3s ease; /* 过渡效果 */
  879. margin-bottom: 20px; /* 每个角色之间的间距 */
  880. padding: 10px; /* 内边距 */
  881. }
  882. /* 置顶角色的样式 */
  883. .role-item.top-role {
  884. background-color: #d3d3d3; /* 灰色背景 */
  885. }
  886. /* 鼠标悬停时的样式 */
  887. .role-item:hover {
  888. background-color: #e6f7ff; /* 悬停时背景色 */
  889. border-color: #1169ff; /* 悬停时边框颜色 */
  890. border-width: 4px; /* 悬停时边框大小 */
  891. border-radius: 15px; /* 悬停时的圆角 */
  892. }
  893. /* 置顶角色在悬停时的样式 */
  894. .role-item.top-role:hover {
  895. background-color: #d3d3d3; /* 保持灰色背景不变 */
  896. border-color: #1169ff; /* 悬停时边框颜色 */
  897. border-width: 4px; /* 悬停时边框大小 */
  898. border-radius: 15px; /* 悬停时的圆角 */
  899. }
  900. .role-item h3 {
  901. margin-top: 0;
  902. }
  903. .role-item ul {
  904. padding-left: 20px;
  905. }
  906. .create-role-button {
  907. background-color: #007aff;
  908. color: white;
  909. border: none;
  910. padding: 10px 20px;
  911. border-radius: 10px;
  912. cursor: pointer;
  913. font-size: 16px;
  914. font-weight: 500;
  915. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  916. transition: background-color 0.3s;
  917. margin-left: 20px; /* 与标题之间的间距 */
  918. }
  919. .create-role-button:hover {
  920. background-color: #005bb5;
  921. }
  922. </style>
  923. </head>
  924. <body>
  925. <div class="sidebar" id="sidebar">
  926. <button onclick="showTable()">License 管理</button>
  927. <button onclick="showUserManagement()">用户管理</button>
  928. <button onclick="showRoleManagement()">角色管理</button>
  929. </div>
  930. <div class="content" id="content">
  931. <button class="toggle-sidebar" onclick="toggleSidebar()">←</button>
  932. <header>
  933. <h1>XUGU License 管理平台</h1>
  934. <div>
  935. <!-- <button class="upload-button" onclick="window.location.href='/static/upload_xlsx/index.html'" style="display: none;">Upload File</button> --> <!-- 默认隐藏 -->
  936. <button class="user-button" onclick="toggleUserInfo()" id="username">User</button>
  937. </div>
  938. </header>
  939. <div id="table-container">
  940. <table id="applications-table">
  941. <thead>
  942. <tr>
  943. <th>创建人</th>
  944. <th>申请日期 <button class="sort-button" onclick="sortTableByDate()">排序</button></th>
  945. <th>关联项目</th>
  946. <th>销售人员</th>
  947. <th>技服人员</th>
  948. <th>总节点数</th>
  949. <th>使用单位</th>
  950. <th>产品名称</th>
  951. <th>版本</th>
  952. <th>节点数</th>
  953. <th>License状态</th>
  954. </tr>
  955. </thead>
  956. <tbody>
  957. </tbody>
  958. </table>
  959. <div class="pagination">
  960. <button id="prev-page">上一页</button>
  961. <button id="next-page">下一页</button>
  962. <select id="page-selector" class="flat-select"></select>
  963. <span id="pagination-info">第 1 页,共 0 页</span> <!-- 新增信息显示区域 -->
  964. <div id="capture-license-button-container">
  965. <!-- 按钮将在这里插入 -->
  966. </div>
  967. <!-- <button class="CaptureLicenseOnce-button" onclick="CaptureLicenseOncefunc()">获取最新license</button> 动态插入按钮的容器 -->
  968. </div>
  969. </div>
  970. <!-- License 详细信息的模态框 -->
  971. <div id="detailsModal" class="modal">
  972. <div class="modal-content">
  973. <span class="close" onclick="closeModal('detailsModal')">&times;</span>
  974. <h3>License 详细信息</h3>
  975. <div id="detailsContent"></div>
  976. <button class="close-button" onclick="closeModal('detailsModal')">关闭</button>
  977. </div>
  978. </div>
  979. <!-- 用户管理的添加用户 -->
  980. <div id="user-management" style="display: none;">
  981. <div style="display: flex; align-items: center; justify-content: space-between;">
  982. <h2>用户管理</h2>
  983. <button id="addUserButton" class="create-role-button" style="display: none;">添加用户</button> <!-- 默认隐藏 -->
  984. </div>
  985. <table id="users-table">
  986. <thead>
  987. <tr>
  988. <th>用户名</th>
  989. <th>电话</th>
  990. <th>邮箱</th>
  991. <th>权限</th>
  992. <th>账号</th>
  993. </tr>
  994. </thead>
  995. <tbody>
  996. </tbody>
  997. </table>
  998. </div>
  999. <!-- 新增的角色管理容器 -->
  1000. <div id="role-management" style="display: none;">
  1001. <div style="display: flex; align-items: center; justify-content: space-between;">
  1002. <h2>角色管理</h2>
  1003. <button id="createRoleButton" class="create-role-button">创建角色</button>
  1004. </div>
  1005. <div id="roles-container"></div>
  1006. </div>
  1007. </div>
  1008. <!-- License 管理的弹出菜单 -->
  1009. <div id="licenseActionModal" class="modal">
  1010. <div class="modal-content action-modal-content" id="licenseActionModalContent">
  1011. <span class="close" onclick="closeModal('licenseActionModal')">&times;</span>
  1012. <!-- <button onclick="showExtraInfo()">查看额外信息</button>
  1013. <button onclick="modifyLicenseInfo()">修改信息</button> 新增的修改信息按钮 -->
  1014. <!-- <button onclick="showDistributionHistory()">分发历史</button>
  1015. <button onclick="confirmDelete()">删除</button> -->
  1016. </div>
  1017. </div>
  1018. <!-- 修改信息的表单框 -->
  1019. <div id="modifyLicenseModal" class="modal">
  1020. <div class="modify-license-modal-content">
  1021. <span class="close" onclick="closeModal('modifyLicenseModal')">&times;</span>
  1022. <h3>修改License信息</h3>
  1023. <form id="modifyLicenseForm">
  1024. <label for="creator">创建人:</label>
  1025. <input type="text" id="creator" name="creator" required><br><br>
  1026. <label for="applicationDate">申请日期:</label>
  1027. <input type="date" id="applicationDate" name="applicationDate" class="form-control" required><br><br>
  1028. <label for="associatedProject">关联项目:</label>
  1029. <input type="text" id="associatedProject" name="associatedProject" required><br><br>
  1030. <label for="salesPerson">销售人员:</label>
  1031. <input type="text" id="salesPerson" name="salesPerson" required><br><br>
  1032. <label for="salesEmail">销售邮箱:</label>
  1033. <input type="email" id="salesEmail" name="salesEmail" required><br><br>
  1034. <label for="supportPerson">技服人员:</label>
  1035. <input type="text" id="supportPerson" name="supportPerson" required><br><br>
  1036. <label for="supportEmail">技服邮箱:</label>
  1037. <input type="email" id="supportEmail" name="supportEmail" required><br><br>
  1038. <label for="totalNodes">总节点数:</label>
  1039. <input type="number" id="totalNodes" name="totalNodes" class="form-control" required><br><br>
  1040. <label for="company">使用单位:</label>
  1041. <input type="text" id="company" name="company" required><br><br>
  1042. <label for="productName">产品名称:</label>
  1043. <input type="text" id="productName" name="productName" required><br><br>
  1044. <label for="version"> 数据库版本: </label>
  1045. <input type="text" id="version" name="version" required><br><br>
  1046. <label for="nodeCount">节点数:</label>
  1047. <input type="number" id="nodeCount" name="nodeCount" class="form-control" required><br><br>
  1048. <button type="button" onclick="saveLicenseChanges()">保存</button>
  1049. </form>
  1050. </div>
  1051. </div>
  1052. <!-- 用户管理的弹出菜单 -->
  1053. <div id="userActionModal" class="modal">
  1054. <div class="modal-content action-modal-content" id="userActionModalContent">
  1055. <span class="close" onclick="closeModal('userActionModal')">&times;</span>
  1056. <button onclick="showMoreUserInfo()">更多用户信息</button>
  1057. <button onclick="showUserLicenseHistory()">查看license分发记录</button>
  1058. <button onclick="modifyUser()">修改用户</button>
  1059. </div>
  1060. </div>
  1061. <!-- 用户管理的添加用户 -->
  1062. <div id="addUserModal" class="modal">
  1063. <div class="centered-modal-content" style="height: 50vh; overflow-y: auto;">
  1064. <span class="close" onclick="closeModal('addUserModal')">&times;</span>
  1065. <h3>添加用户</h3>
  1066. <form id="addUserForm">
  1067. <div class="form-group">
  1068. <label for="addUsername">用户名:</label>
  1069. <input type="text" id="addUsername" name="username" class="flat-rounded-input" required>
  1070. </div>
  1071. <div class="form-group">
  1072. <label for="addPassword">密码:</label>
  1073. <input type="password" id="addPassword" name="password" class="flat-rounded-input" required>
  1074. </div>
  1075. <div class="form-group">
  1076. <label for="addAccount">账号:</label>
  1077. <input type="text" id="addAccount" name="account" class="flat-rounded-input" required>
  1078. </div>
  1079. <div class="form-group">
  1080. <label for="addTelephone">电话:</label>
  1081. <input type="text" id="addTelephone" name="telephone" class="flat-rounded-input" required>
  1082. </div>
  1083. <div class="form-group">
  1084. <label for="addEmail">邮箱:</label>
  1085. <input type="email" id="addEmail" name="email" class="flat-rounded-input" required>
  1086. </div>
  1087. <button type="button" onclick="saveNewUser()" class="flat-rounded-button">保存</button>
  1088. </form>
  1089. </div>
  1090. </div>
  1091. <!-- 邮箱和用户选择弹出框 -->
  1092. <div id="emailModal" class="modal">
  1093. <div class="modal-content centered-modal-content" style="height: 45vh; overflow-y: auto;">
  1094. <span class="close" onclick="closeModal('emailModal')">&times;</span>
  1095. <!-- 邮箱输入部分 -->
  1096. <label for="emailInput1" class="email-modal-label">选中要发送的邮箱:</label>
  1097. <div id="emailInputs">
  1098. <input type="text" id="emailInput1" class="email-modal-input">
  1099. </div>
  1100. <br>
  1101. <button onclick="addEmailInput()" class="add-email-button">添加邮箱</button>
  1102. <!-- 用户选择部分 -->
  1103. <label for="userSelect1" class="email-modal-label">选择要分发的用户:</label>
  1104. <div id="userInputs"></div>
  1105. <button onclick="addUserInput()" class="add-email-button">添加用户</button>
  1106. <!-- 发送按钮 -->
  1107. <button onclick="sendEmail()" class="ios-button">发送</button>
  1108. </div>
  1109. </div>
  1110. <!-- 其他模态框不变 -->
  1111. <div id="extraInfoModal" class="modal">
  1112. <div class="modal-content">
  1113. <span class="close" onclick="closeModal('extraInfoModal')">&times;</span>
  1114. <div id="extraInfoContent" class="extra-info"></div>
  1115. </div>
  1116. </div>
  1117. <div id="userModal" class="user-info">
  1118. <span class="close apple-close" onclick="closeUserInfo()">&times;</span> <!-- 关闭按钮 -->
  1119. <div id="userInfoContent"></div>
  1120. <br>
  1121. <button class="apple-logout-button" onclick="logout()">退出</button>
  1122. </div>
  1123. <!-- license删除模态框-->
  1124. <div id="confirmDeleteModal" class="modal">
  1125. <div class="centered-modal-content">
  1126. <span class="close" onclick="closeModal('confirmDeleteModal')">&times;</span>
  1127. </div>
  1128. </div>
  1129. <div id="confirmGenerateModal" class="modal">
  1130. <div class="centered-modal-content" style="height: 15vh; overflow-y: auto;">
  1131. <span class="close" onclick="closeModal('confirmGenerateModal')">&times;</span>
  1132. <p>确认生成License吗?</p>
  1133. <button id="confirm-generate-button">确认</button>
  1134. <button onclick="closeModal('confirmGenerateModal')">取消</button>
  1135. </div>
  1136. </div>
  1137. <div id="distributionHistoryModal" class="modal">
  1138. <div class="centered-modal-content">
  1139. <span class="close" onclick="closeModal('distributionHistoryModal')">&times;</span>
  1140. <h3>分发历史</h3>
  1141. <div id="distributionHistoryContent" class="extra-info"></div>
  1142. </div>
  1143. </div>
  1144. <script>
  1145. //翻页有关,还需优化
  1146. let currentPage = 1;
  1147. let pageSize = 10;
  1148. let LisOffset = 1;
  1149. let totalPages = 0; // 存储总页数
  1150. let selectedPage =1;
  1151. let nextPage =1;
  1152. let prevPage = 10;
  1153. //用户token
  1154. const token = localStorage.getItem('Authorization');
  1155. //选中行的数据
  1156. let selectedRowData = null;//选中行的数据
  1157. let isAscending = true;
  1158. let userMap = {}; // 用于存储用户名和用户ID的映射
  1159. let currentUserRole = ''; // 新增变量存储当前用户的权限
  1160. let currentUserName = ''; // 新增变量存储当前用户的名字
  1161. let userPermissions = [];// 全局变量,用于存储用户权限
  1162. let LicApplicationData = []; // 全局变量存储数据
  1163. let currentRolePermissions = []; // 这是您获取的当前角色的权限列表
  1164. function checkPermission(permission) {
  1165. console.log(`检查权限: ${permission} - ${hasPermission ? '有权限' : '无权限'}`);
  1166. return userPermissions.includes(permission);
  1167. }
  1168. async function initialize() {
  1169. await fetchUsername(); // 确保 fetchUsername 完成
  1170. fetchApplications(1, 10); // 然后再调用 fetchApplications
  1171. }
  1172. //获取license展示信息
  1173. function fetchApplications(page, size) {
  1174. fetch(`http://127.0.0.1:8080/api/admin/GetAllLicenseInfo?page=${page}&pageSize=${size}`, {
  1175. method: 'GET',
  1176. headers: {
  1177. 'Authorization': `Bearer ${token}`,
  1178. 'Content-Type': 'application/json'
  1179. }
  1180. })
  1181. .then(response => response.json())
  1182. .then(data => {
  1183. //selectedRowData = data.data;
  1184. LicApplicationData = data.data; // 将接收到的数据存储到全局变量
  1185. console.log("lic数据",data); // 输出获取的数据结构
  1186. console.log("z该死的权限数组",userPermissions);
  1187. const hasGeneratePermission = userPermissions.includes("generate_license");
  1188. const hasDistributePermission = userPermissions.includes("dispat_license");
  1189. // 更新总页数
  1190. //totalPages = Math.ceil(data.total / 10);
  1191. // 在控制台打印权限结果
  1192. console.log(`hasGeneratePermission: ${hasGeneratePermission}, hasDistributePermission: ${hasDistributePermission}`);
  1193. totalPages = Math.ceil(data.total / 10);
  1194. const tableBody = document.querySelector('#applications-table tbody');
  1195. const tableHead = document.querySelector('#applications-table thead tr');
  1196. tableBody.innerHTML = '';
  1197. tableHead.innerHTML = `
  1198. <th></th> <!-- 添加一个空的表头用于放置下拉按钮 -->
  1199. <th>创建人</th>
  1200. <th>申请日期 </th>
  1201. <!-- <th>申请日期 <button class="sort-button" onclick="sortTableByDate()">排序</button></th>-->
  1202. <th>关联项目</th>
  1203. <th>销售人员</th>
  1204. <th>技服人员</th>
  1205. <th>总节点数</th>
  1206. <th>使用单位</th>
  1207. <th>操作</th> <!-- 新增的表头用于显示操作按钮 -->
  1208. `;
  1209. data.data.forEach(applicationArray => {
  1210. const firstApplication = applicationArray[0];
  1211. let showGenerateButton = false;
  1212. // Check if any child row has LicenseFlage as "未生成"
  1213. applicationArray.forEach(detail => {
  1214. if (detail.LicenseFlage === "未生成") {
  1215. showGenerateButton = true;
  1216. }
  1217. });
  1218. // 创建主行
  1219. const row = document.createElement('tr');
  1220. const dropdownButton = document.createElement('button');
  1221. // 使用CSS创建一个箭头图标
  1222. dropdownButton.innerHTML = '';
  1223. dropdownButton.classList.add('arrow-icon');
  1224. dropdownButton.style.cursor = 'pointer';
  1225. row.innerHTML = `
  1226. <td></td> <!-- 空的单元格用于放置下拉按钮 -->
  1227. <td>${createEllipsisText(firstApplication.Creator)}</td>
  1228. <td>${createEllipsisText(firstApplication.ApplicationDate)} ${firstApplication.ApplicationTime}</td>
  1229. <td>${createEllipsisText(firstApplication.GlxmName)}</td>
  1230. <td>${createEllipsisText(firstApplication.SalesPerson)}</td>
  1231. <td>${createEllipsisText(firstApplication.SupportPerson)}</td>
  1232. <td>${firstApplication.TotalNodes}</td>
  1233. <td>${createEllipsisText(firstApplication.Company)}</td>
  1234. `;
  1235. row.querySelector('td').appendChild(dropdownButton);
  1236. // 添加 License 状态按钮 (父级行)
  1237. if (hasGeneratePermission || hasDistributePermission) {
  1238. const licenseStatusCell = document.createElement('td');
  1239. if (hasGeneratePermission && showGenerateButton) {
  1240. licenseStatusCell.innerHTML += `<button class="license-status-btn generate" onclick="confirmGenerateLicense('${firstApplication.oa_request_id}', true)">生成</button>`;
  1241. } else if (hasDistributePermission && firstApplication.LicenseFlage === "已生成") {
  1242. licenseStatusCell.innerHTML += `<button class="license-status-btn distribute" onclick="showEmailModal('${firstApplication.SupportEmail}', '${firstApplication.SalesEmail}','','${firstApplication.oa_request_id}')">分发</button>`;
  1243. }
  1244. // 添加一个分隔符
  1245. licenseStatusCell.innerHTML += `<span style="margin: 0 10px; display: inline-block; width: 1px; height: 20px; background-color: #ccc;"></span>`;
  1246. // 在这里添加“查看详情”按钮
  1247. licenseStatusCell.innerHTML += `<button class="license-status-btn view-details" onclick="showDetailsModal('${firstApplication.UniqueID}', false)">查看详情</button>`;
  1248. row.appendChild(licenseStatusCell);
  1249. }
  1250. tableBody.appendChild(row);
  1251. // 多行内容及表头 (子行)
  1252. const detailRow = document.createElement('tr');
  1253. const detailCell = document.createElement('td');
  1254. detailCell.colSpan = 11; // 占满所有列
  1255. detailCell.style.display = 'none';
  1256. const detailTable = document.createElement('table');
  1257. // 添加表头
  1258. const detailTableHeader = document.createElement('tr');
  1259. detailTableHeader.innerHTML = `
  1260. <th>产品名称</th>
  1261. <th>版本</th>
  1262. <th>节点数</th>
  1263. <th>处理器</th>
  1264. <th>操作系统</th>
  1265. <th>主MAC地址</th>
  1266. <th>副MAC地址</th>
  1267. <th> 查看</th>
  1268. `;
  1269. detailTable.appendChild(detailTableHeader);
  1270. // 添加详细信息行 (子行)
  1271. applicationArray.forEach(detail => {
  1272. const detailInnerRow = document.createElement('tr');
  1273. detailInnerRow.innerHTML = `
  1274. <td>${createEllipsisText(detail.ProductName)}</td>
  1275. <td>${createEllipsisText(detail.ProductVersion)}</td>
  1276. <td>${detail.NodeCount}</td>
  1277. <td>${createEllipsisText(detail.oa_cpu)}</td>
  1278. <td>${createEllipsisText(detail.oa_operating_system)}</td>
  1279. <td>${createEllipsisText(detail.oa_main_mac)}</td>
  1280. <td>${createEllipsisText(detail.oa_second_mac)}</td>
  1281. `;
  1282. //保留这里的代码,涉及到子行的单独申请
  1283. // 添加 License 状态按钮 (子行)
  1284. // if (hasGeneratePermission || hasDistributePermission) {
  1285. // const licenseStatusDetailCell = document.createElement('td');
  1286. // if (hasGeneratePermission && detail.LicenseFlage === "未生成") {
  1287. // // 子行点击生成按钮时,传递 UniqueID 和 false 表示这是子行
  1288. // licenseStatusDetailCell.innerHTML = `<button class="license-status-btn generate" onclick="confirmGenerateLicense('${detail.UniqueID}', false)">生成</button>`;
  1289. // } else if (hasDistributePermission && detail.LicenseFlage === "已生成") {
  1290. // // 子行点击分发按钮时,传递 UniqueID 用于分发操作
  1291. // licenseStatusDetailCell.innerHTML = `<button class="license-status-btn distribute" onclick="showEmailModal('${detail.SupportEmail}', '${detail.SalesEmail}', '${detail.UniqueID}','')">分发</button>`;
  1292. // }
  1293. // detailInnerRow.appendChild(licenseStatusDetailCell);
  1294. // }
  1295. detailTable.appendChild(detailInnerRow);
  1296. // 添加“查看详情”按钮 (子行)
  1297. // const viewDetailsCell = document.createElement('td');
  1298. // viewDetailsCell.innerHTML = `<button class="license-status-btn view-details" onclick="showDetailsModal('${detail.UniqueID}', true)">查看详情</button>`;
  1299. // detailInnerRow.appendChild(viewDetailsCell);
  1300. // detailTable.appendChild(detailInnerRow);
  1301. // 仅当主行状态为“分发”时添加“下载lic”按钮
  1302. // 创建一个新的单元格用于放置按钮
  1303. const actionCell = document.createElement('td');
  1304. // 创建按钮容器
  1305. const buttonContainer = document.createElement('div');
  1306. buttonContainer.classList.add('button-container');
  1307. // 创建“查看详情”按钮 (子行)
  1308. const viewDetailsButton = document.createElement('button');
  1309. viewDetailsButton.classList.add('license-status-btn', 'view-details');
  1310. viewDetailsButton.textContent = '查看详情';
  1311. viewDetailsButton.onclick = () => showDetailsModal(detail.UniqueID, true);
  1312. // 将“查看详情”按钮添加到按钮容器
  1313. buttonContainer.appendChild(viewDetailsButton);
  1314. // 仅当主行状态为“已生成”时添加“下载lic”按钮
  1315. if (firstApplication.LicenseFlage === "已生成") {
  1316. const downloadLicButton = document.createElement('button');
  1317. downloadLicButton.classList.add('license-status-btn', 'download-lic');
  1318. downloadLicButton.textContent = '下载lic';
  1319. // 绑定当前行的 lic1 和 lic2 数据
  1320. downloadLicButton.onclick = () => downloadLicenseFiles(detail.lic1, detail.lic2);
  1321. // 将“下载lic”按钮添加到按钮容器
  1322. buttonContainer.appendChild(downloadLicButton);
  1323. }
  1324. // 将按钮容器添加到actionCell
  1325. actionCell.appendChild(buttonContainer);
  1326. // 将actionCell添加到当前子行
  1327. detailInnerRow.appendChild(actionCell);
  1328. // 将子行添加到详细信息表格
  1329. detailTable.appendChild(detailInnerRow);
  1330. // 为每个详细信息行添加点击事件 (子行)
  1331. detailInnerRow.addEventListener('click', (event) => {
  1332. if (!event.target.closest('button')) {
  1333. openActionModal(event, detail, 'licenseActionModal');
  1334. }
  1335. });
  1336. detailInnerRow.addEventListener('contextmenu', (event) => {
  1337. event.preventDefault();
  1338. if (!event.target.closest('button')) {
  1339. openActionModal(event, detail, 'licenseActionModal');
  1340. }
  1341. });
  1342. });
  1343. detailCell.appendChild(detailTable);
  1344. detailRow.appendChild(detailCell);
  1345. tableBody.appendChild(detailRow);
  1346. // 主行的点击事件,用于切换下拉菜单的显示隐藏
  1347. // row.addEventListener('click', (event) => {
  1348. // if (!event.target.closest('button')) { // 如果点击的不是按钮
  1349. // detailCell.style.display = detailCell.style.display === 'none' ? 'table-cell' : 'none';
  1350. // }
  1351. // });
  1352. // // 点击下拉按钮切换显示隐藏
  1353. // dropdownButton.addEventListener('click', (event) => {
  1354. // event.stopPropagation(); // 阻止事件冒泡到行点击事件
  1355. // detailCell.style.display = detailCell.style.display === 'none' ? 'table-cell' : 'none';
  1356. // });
  1357. row.addEventListener('click', (event) => {
  1358. if (!event.target.closest('button')) { // 如果点击的不是按钮
  1359. // const isExpanded = detailCell.style.display === 'table-cell';
  1360. // detailCell.style.display = isExpanded ? 'none' : 'table-cell';
  1361. // row.classList.toggle('expanded-row', !isExpanded);
  1362. // dropdownButton.classList.toggle('rotate-arrow', !isExpanded); // 旋转箭头图标
  1363. if (!event.target.closest('button')) {
  1364. const isExpanded = detailCell.style.display === 'table-cell';
  1365. // 收回其他行
  1366. closeAllExpandedRows();
  1367. // 展开/收起当前行
  1368. detailCell.style.display = isExpanded ? 'none' : 'table-cell';
  1369. row.classList.toggle('expanded-row', !isExpanded);
  1370. dropdownButton.classList.toggle('rotate-arrow', !isExpanded);
  1371. }
  1372. }
  1373. });
  1374. dropdownButton.addEventListener('click', (event) => {
  1375. // event.stopPropagation(); // 阻止事件冒泡到行点击事件
  1376. // const isExpanded = detailCell.style.display === 'table-cell';
  1377. // detailCell.style.display = isExpanded ? 'none' : 'table-cell';
  1378. // row.classList.toggle('expanded-row', !isExpanded);
  1379. // dropdownButton.classList.toggle('rotate-arrow', !isExpanded); // 旋转箭头图标
  1380. event.stopPropagation(); // 阻止事件冒泡到行点击事件
  1381. const isExpanded = detailCell.style.display === 'table-cell';
  1382. // 收回其他行
  1383. closeAllExpandedRows();
  1384. // 展开/收起当前行
  1385. detailCell.style.display = isExpanded ? 'none' : 'table-cell';
  1386. row.classList.toggle('expanded-row', !isExpanded);
  1387. dropdownButton.classList.toggle('rotate-arrow', !isExpanded);
  1388. });
  1389. });
  1390. // 分页和其他控制逻辑
  1391. // 更新分页信息
  1392. // totalPages = Math.ceil(data.total / pageSize);
  1393. document.getElementById('pagination-info').textContent = `第 ${currentPage} 页,共 ${totalPages} 页`;
  1394. document.getElementById('prev-page').disabled = currentPage <= 1;
  1395. document.getElementById('next-page').disabled = currentPage >= totalPages;
  1396. const pageSelector = document.getElementById('page-selector');
  1397. pageSelector.innerHTML = '';
  1398. for (let i = 1; i <= totalPages; i++) {
  1399. const option = document.createElement('option');
  1400. option.value = i;
  1401. option.text = i;
  1402. if (i === selectedPage) {
  1403. option.selected = true;
  1404. document.getElementById('pagination-info').textContent = `第 ${selectedPage} 页,共 ${totalPages} 页`;
  1405. // LisOffset = selectedPage
  1406. // pageSize = LisOffset + 10;
  1407. // document.getElementById('prev-page').disabled = currentPage <= 1;
  1408. // document.getElementById('next-page').disabled = currentPage >= totalPages;
  1409. }
  1410. pageSelector.appendChild(option);
  1411. }
  1412. });
  1413. }
  1414. function checkCaptureLicensePermission() {
  1415. // 获取插入按钮的容器元素
  1416. const container = document.getElementById('capture-license-button-container');
  1417. if (container) { // 确保容器元素存在
  1418. if (userPermissions.includes('capture_license_once_to_db')) {
  1419. // 如果有权限,插入按钮
  1420. const CaptureLicensebuttonHtml = `<button class="CaptureLicenseOnce-button" onclick="CaptureLicenseOncefunc()">获取最新license</button>`;
  1421. container.innerHTML = CaptureLicensebuttonHtml;
  1422. } else {
  1423. // 如果没有权限,确保不显示按钮
  1424. container.innerHTML = ''; // 清空容器
  1425. }
  1426. } else {
  1427. console.error('找不到 capture-license-button-container 元素');
  1428. }
  1429. }
  1430. let currentOffset = 1;
  1431. const itemsPerPage = 10;
  1432. // 添加页数选择框的事件监听器
  1433. document.getElementById('page-selector').addEventListener('change', (event) => {
  1434. selectedPage = parseInt(event.target.value, 10);
  1435. const startRecord = (selectedPage - 1) * 10 + 1;
  1436. const endRecord = startRecord + 10;
  1437. LisOffset = selectedPage
  1438. pageSize = LisOffset* 10;
  1439. currentPage = selectedPage
  1440. currentOffset = startRecord
  1441. endOffset = endRecord
  1442. fetchApplications(startRecord, endRecord);
  1443. });
  1444. // 分页按钮事件监听器
  1445. document.getElementById('prev-page').addEventListener('click', () => {
  1446. if (currentPage > 1) {
  1447. currentPage--;
  1448. selectedPage--
  1449. currentOffset -= itemsPerPage;
  1450. const startOffset = currentOffset;
  1451. const endOffset = currentOffset + itemsPerPage - 1;
  1452. fetchApplications(startOffset, endOffset);
  1453. }
  1454. });
  1455. document.getElementById('next-page').addEventListener('click', () => {
  1456. if (currentPage < totalPages) {
  1457. currentPage++
  1458. selectedPage++
  1459. LisOffset += pageSize-LisOffset;
  1460. pageSize += 10; // 增加页数时,增加 pageSize,规则可自定义
  1461. currentOffset += itemsPerPage;
  1462. const startOffset = currentOffset;
  1463. const endOffset = currentOffset + itemsPerPage - 1;
  1464. fetchApplications(startOffset, endOffset);
  1465. }
  1466. });
  1467. // 页面加载时默认调用第一页的数据
  1468. //fetchApplications(1);
  1469. // 页面初始化时调用 fetchUsername 函数
  1470. //fetchApplications(LisOffset,pageSize);
  1471. //排序
  1472. // function sortTableByDate() {
  1473. // applicationData.sort((a, b) => {
  1474. // const dateTimeA = `${a[0].ApplicationDate} ${a[0].ApplicationTime}`;
  1475. // const dateTimeB = `${b[0].ApplicationDate} ${b[0].ApplicationTime}`;
  1476. // return isAscending ? dateTimeA.localeCompare(dateTimeB) : dateTimeB.localeCompare(dateTimeA);
  1477. // });
  1478. // renderTable(applicationData); // 排序后重新渲染表格
  1479. // isAscending = !isAscending; // 切换排序顺序
  1480. // }
  1481. // 关闭所有已经展开的行
  1482. function closeAllExpandedRows() {
  1483. const allExpandedRows = document.querySelectorAll('.expanded-row');
  1484. allExpandedRows.forEach(expandedRow => {
  1485. const detailCell = expandedRow.nextElementSibling.querySelector('td');
  1486. if (detailCell && detailCell.style.display === 'table-cell') {
  1487. detailCell.style.display = 'none';
  1488. expandedRow.classList.remove('expanded-row');
  1489. const dropdownButton = expandedRow.querySelector('.arrow-icon');
  1490. if (dropdownButton) {
  1491. dropdownButton.classList.remove('rotate-arrow');
  1492. }
  1493. }
  1494. });
  1495. }
  1496. // 创建带省略号的文本,并在鼠标悬停时显示完整内容
  1497. function createEllipsisText(text) {
  1498. const maxLength = 20; // 最大显示字符数
  1499. if (text == null || typeof text !== 'string') {
  1500. return ''; // 如果 text 是 null、undefined 或不是字符串,返回空字符串
  1501. }
  1502. if (text.length > maxLength) {
  1503. const span = document.createElement('span');
  1504. span.textContent = text.substring(0, maxLength) + '...';
  1505. span.title = text; // 鼠标悬停时显示完整内容
  1506. return span.outerHTML;
  1507. }
  1508. return text;
  1509. }
  1510. //生成licensestr
  1511. function confirmGenerateLicense(id, isParentRow) {
  1512. const confirmGenerateModal = document.getElementById('confirmGenerateModal');
  1513. confirmGenerateModal.style.display = 'block';
  1514. document.getElementById('confirm-generate-button').onclick = function() {
  1515. generateLicense(id, isParentRow);
  1516. };
  1517. }
  1518. function generateLicense(id, isParentRow) {
  1519. const payload = isParentRow ? { oa_request_id: id } : { uniqueID: id };
  1520. fetch('http://127.0.0.1:8080/api/admin/GenerateLicense', {
  1521. method: 'POST',
  1522. headers: {
  1523. 'Authorization': `Bearer ${token}`,
  1524. 'Content-Type': 'application/json'
  1525. },
  1526. body: JSON.stringify(payload)
  1527. })
  1528. .then(response => response.json())
  1529. .then(data => {
  1530. if (data.success) {
  1531. alert('License生成成功!');
  1532. const startOffset = currentOffset; // 当前的起始位置
  1533. const endOffset = startOffset + itemsPerPage - 1; // 计算结束位置
  1534. fetchApplications(startOffset, endOffset); // 传入计算好的起始和结束位置
  1535. // fetchApplications(LisOffset, pageSize);
  1536. } else {
  1537. alert('License生成失败:' + data.error);
  1538. }
  1539. closeModal('confirmGenerateModal');
  1540. });
  1541. }
  1542. //主动抓取一次Licen数据
  1543. function CaptureLicenseOncefunc() {
  1544. // 显示加载模态框
  1545. const loadingModal = document.createElement('div');
  1546. loadingModal.classList.add('modal-content', 'apple-modal-content');
  1547. loadingModal.innerHTML = `
  1548. <h3>正在获取 License 信息...</h3>
  1549. <div class="progress-bar" style="width: 100%; height: 20px; background-color: #e0e0e0;">
  1550. <div class="progress" style="width: 50%; height: 100%; background-color: #007aff;"></div>
  1551. </div>
  1552. `;
  1553. document.body.appendChild(loadingModal);
  1554. // 定义超时函数
  1555. const timeoutPromise = new Promise((_, reject) => {
  1556. setTimeout(() => {
  1557. reject(new Error('获取超时'));
  1558. }, 10000); // 10秒超时
  1559. });
  1560. // 发起 GET 请求的 Promise
  1561. const fetchPromise = fetch('http://127.0.0.1:8080/api/admin/GetCaptureLicenseOnce', {
  1562. method: 'GET',
  1563. headers: {
  1564. 'Authorization': `Bearer ${token}`,
  1565. 'Content-Type': 'application/json'
  1566. }
  1567. }).then(response => response.json());
  1568. // 使用 Promise.race 来竞争两个 Promise,哪个先返回就使用哪个
  1569. Promise.race([fetchPromise, timeoutPromise])
  1570. .then(data => {
  1571. // 先关闭进度条
  1572. document.body.removeChild(loadingModal);
  1573. // 显示成功或失败提示
  1574. if (data.success) {
  1575. alert('License 获取成功!');
  1576. } else {
  1577. alert('获取失败:' + data.error);
  1578. }
  1579. })
  1580. .catch(error => {
  1581. // 先关闭进度条
  1582. document.body.removeChild(loadingModal);
  1583. // 显示错误提示
  1584. alert(error.message); // 如果超时或请求失败
  1585. });
  1586. }
  1587. function downloadLicenseFiles(lic1, lic2) {
  1588. // 下载license.dat文件
  1589. if (lic1) {
  1590. const blob1 = new Blob([lic1], { type: 'text/plain' });
  1591. const link1 = document.createElement('a');
  1592. link1.href = URL.createObjectURL(blob1);
  1593. link1.download = 'license.dat';
  1594. link1.click();
  1595. }
  1596. // 如果lic2不为空,下载license2.dat文件
  1597. if (lic2) {
  1598. const blob2 = new Blob([lic2], { type: 'text/plain' });
  1599. const link2 = document.createElement('a');
  1600. link2.href = URL.createObjectURL(blob2);
  1601. link2.download = 'license2.dat';
  1602. link2.click();
  1603. }
  1604. }
  1605. //查看lic所有信息
  1606. // 查看lic所有信息
  1607. function showDetailsModal(uniqueID, isChildRow = false) {
  1608. console.log("当前 uniqueID:", uniqueID);
  1609. console.log("当前 isChildRow:", isChildRow);
  1610. let selectedData = null;
  1611. // 查找主行和子行数据
  1612. console.log("查找主行和子行数据");
  1613. let selectedApplicationArray = null;
  1614. for (let applicationArray of LicApplicationData) {
  1615. if (applicationArray.some(data => data.UniqueID === uniqueID)) {
  1616. selectedApplicationArray = applicationArray;
  1617. break;
  1618. }
  1619. }
  1620. if (!selectedApplicationArray) {
  1621. console.error('未找到对应的记录,UniqueID:', uniqueID);
  1622. alert('未找到对应的记录,请检查数据');
  1623. return;
  1624. }
  1625. let detailsHtml = `<table class="details-table" style="width:100%;">`;
  1626. // 如果是子行,直接显示该子行的信息
  1627. if (isChildRow) {
  1628. const childData = selectedApplicationArray.find(data => data.UniqueID === uniqueID);
  1629. if (childData) {
  1630. detailsHtml += `
  1631. <tr>
  1632. <th style="width: 50px;">序号</th><th>产品名称</th><th>版本</th><th>节点数</th><th>处理器</th>
  1633. <th>操作系统</th><th>主MAC地址</th><th>副MAC地址</th><th>License状态</th> <!-- 新增 License 状态列 -->
  1634. </tr>
  1635. <tr>
  1636. <td style="width: 50px;">${childData.oa_id}</td><td>${childData.ProductName}</td><td>${childData.ProductVersion}</td><td>${childData.NodeCount}</td>
  1637. <td>${childData.oa_cpu}</td><td>${childData.oa_operating_system}</td><td>${childData.oa_main_mac}</td><td>${childData.oa_second_mac}</td>
  1638. <td>${childData.LicenseFlage}</td> <!-- 显示 License 状态 -->
  1639. </tr>
  1640. `;
  1641. } else {
  1642. detailsHtml += `<tr><td colspan="9">未找到对应的子行记录。</td></tr>`;
  1643. }
  1644. } else {
  1645. // 如果是主行,显示主行和所有子行信息
  1646. const firstData = selectedApplicationArray[0];
  1647. detailsHtml += `
  1648. <tr>
  1649. <th>创建人</th><th>申请日期</th><th>关联项目</th><th>销售人员</th>
  1650. <th>技服人员</th><th>总节点数</th><th>使用单位</th>
  1651. </tr>
  1652. <tr>
  1653. <td>${firstData.Creator}</td><td>${firstData.ApplicationDate}</td><td>${firstData.GlxmName}</td>
  1654. <td>${firstData.SalesPerson}</td><td>${firstData.SupportPerson}</td><td>${firstData.TotalNodes}</td>
  1655. <td>${firstData.Company}</td>
  1656. </tr>
  1657. `;
  1658. // 按 oa_id 对子行数据进行排序(升序)
  1659. const sortedApplicationArray = selectedApplicationArray.slice(1).sort((a, b) => a.oa_id - b.oa_id);
  1660. // 显示子行信息
  1661. detailsHtml += `
  1662. <tr>
  1663. <th style="width: 50px;">序号</th><th>产品名称</th><th>版本</th><th>节点数</th><th>处理器</th>
  1664. <th>操作系统</th><th>主MAC地址</th><th>副MAC地址</th><th>License状态</th> <!-- 新增 License 状态列 -->
  1665. </tr>
  1666. `;
  1667. sortedApplicationArray.forEach((data, index) => {
  1668. detailsHtml += `
  1669. <tr>
  1670. <td style="width: 50px;">${index + 1}</td><td>${data.ProductName}</td><td>${data.ProductVersion}</td><td>${data.NodeCount}</td>
  1671. <td>${data.oa_cpu}</td><td>${data.oa_operating_system}</td><td>${data.oa_main_mac}</td><td>${data.oa_second_mac}</td>
  1672. <td>${data.LicenseFlage}</td> <!-- 显示 License 状态 -->
  1673. </tr>
  1674. `;
  1675. });
  1676. }
  1677. detailsHtml += `</table>`;
  1678. document.getElementById('detailsContent').innerHTML = detailsHtml;
  1679. document.getElementById('detailsModal').style.display = 'block';
  1680. }
  1681. // 用户管理菜单栏
  1682. function openUserActionModal(event, data, modalId) {
  1683. selectedRowData = data;
  1684. let modal = document.getElementById(modalId);
  1685. const modalContent = modal.querySelector('.modal-content');
  1686. // 清空之前的内容
  1687. modalContent.innerHTML = `
  1688. <span class="close" onclick="closeModal('${modalId}')">&times;</span>
  1689. `;
  1690. // 动态生成更多用户信息按钮
  1691. if (userPermissions.includes('read_user')) {
  1692. modalContent.innerHTML += `<button onclick="showMoreUserInfo(); closeModal('${modalId}');">更多用户信息</button>`;
  1693. }
  1694. // 检查是否有 `update_user` 权限,决定是否显示修改用户按钮
  1695. if (userPermissions.includes('update_user')) {
  1696. modalContent.innerHTML += `<button onclick="modifyUser(); closeModal('${modalId}');">修改用户</button>`;
  1697. }
  1698. // 检查是否有 `delete_user` 权限,决定是否显示删除按钮
  1699. if (userPermissions.includes('delete_user')) {
  1700. modalContent.innerHTML += `<button onclick="confirmDeleteUser('${data.UniqueID}'); closeModal('${modalId}');">删除用户</button>`;
  1701. }
  1702. // 显示菜单位置
  1703. modalContent.style.top = `${event.clientY}px`;
  1704. modalContent.style.left = `${event.clientX}px`;
  1705. modal.style.display = 'block';
  1706. }
  1707. // 为用户管理界面的每一行添加点击和右键事件监听器
  1708. function fetchUsers() {
  1709. fetch('http://127.0.0.1:8080/api/admin/userInfoAll', {
  1710. method: 'GET',
  1711. headers: {
  1712. 'Authorization': `Bearer ${token}`,
  1713. 'Content-Type': 'application/json'
  1714. }
  1715. })
  1716. .then(response => response.json())
  1717. .then(data => {
  1718. const tableBody = document.querySelector('#users-table tbody');
  1719. tableBody.innerHTML = '';
  1720. data.data.forEach(user => {
  1721. // 如果 ACCOUNT 字段为 'admin',则跳过这一行
  1722. if (user.Account === 'admin') {
  1723. return;
  1724. }
  1725. const row = document.createElement('tr');
  1726. row.innerHTML = `
  1727. <td>${user.Username}</td>
  1728. <td>${user.Telephone}</td>
  1729. <td>${user.Email}</td>
  1730. <td>${user.Role}</td>
  1731. <td>${user.Account}</td>
  1732. `;
  1733. row.addEventListener('click', (event) => {
  1734. if (!event.target.classList.contains('ios-button')) {
  1735. openUserActionModal(event, user, 'userActionModal');
  1736. }
  1737. });
  1738. row.addEventListener('contextmenu', (event) => {
  1739. event.preventDefault();
  1740. if (!event.target.classList.contains('ios-button')) {
  1741. openUserActionModal(event, user, 'userActionModal');
  1742. }
  1743. });
  1744. tableBody.appendChild(row);
  1745. });
  1746. });
  1747. }
  1748. //查看用户lic历史
  1749. function showUserLicenseHistory() {
  1750. fetch(`http://127.0.0.1:8080/api/admin/GetlicenseRecordInfoByUser`, {
  1751. method: 'POST',
  1752. headers: {
  1753. 'Authorization': `Bearer ${token}`,
  1754. 'Content-Type': 'application/json'
  1755. },
  1756. body: JSON.stringify({
  1757. Id: selectedRowData.Id,
  1758. UserName: selectedRowData.Username,
  1759. Page: 1,
  1760. PageSize: 10
  1761. })
  1762. })
  1763. .then(response => response.json())
  1764. .then(data => {
  1765. const extraInfoContent = document.getElementById('extraInfoContent');
  1766. extraInfoContent.innerHTML = `<h3>License 分发记录</h3>`;
  1767. if (data.data && data.data.length > 0) {
  1768. const table = document.createElement('table');
  1769. table.style.width = '100%';
  1770. table.style.borderCollapse = 'collapse';
  1771. table.style.marginTop = '10px';
  1772. const thead = document.createElement('thead');
  1773. const headerRow = document.createElement('tr');
  1774. const headers = ['分发日期', '关联项目', '产品名称', '版本', '节点数', 'Company'];
  1775. headers.forEach(headerText => {
  1776. const th = document.createElement('th');
  1777. th.textContent = headerText;
  1778. th.style.border = '1px solid #ddd';
  1779. th.style.padding = '8px';
  1780. th.style.backgroundColor = '#f1f1f1';
  1781. headerRow.appendChild(th);
  1782. });
  1783. thead.appendChild(headerRow);
  1784. table.appendChild(thead);
  1785. const tbody = document.createElement('tbody');
  1786. data.data.forEach(record => {
  1787. const row = document.createElement('tr');
  1788. const cells = [
  1789. record.up_time.Time,
  1790. record.AssociatedProject,
  1791. record.ProductName,
  1792. record.Version,
  1793. record.NodeCount,
  1794. record.Company
  1795. ];
  1796. cells.forEach(cellText => {
  1797. const td = document.createElement('td');
  1798. td.textContent = cellText;
  1799. td.style.border = '1px solid #ddd';
  1800. td.style.padding = '8px';
  1801. row.appendChild(td);
  1802. });
  1803. tbody.appendChild(row);
  1804. });
  1805. table.appendChild(tbody);
  1806. extraInfoContent.appendChild(table);
  1807. } else {
  1808. extraInfoContent.innerHTML += `<p>没有找到分发记录。</p>`;
  1809. }
  1810. document.getElementById('extraInfoModal').style.display = 'block';
  1811. });
  1812. }
  1813. //用户菜单栏
  1814. function openActionModal(event, data, modalId) {
  1815. selectedRowData = data;
  1816. let modal = document.getElementById(modalId);
  1817. const modalContent = modal.querySelector('.modal-content');
  1818. // 清空之前的内容
  1819. modalContent.innerHTML = `
  1820. <span class="close" onclick="closeModal('${modalId}')">&times;</span>
  1821. `;
  1822. // 动态生成查看分发记录
  1823. if (userPermissions.includes('read_license_record')) {
  1824. modalContent.innerHTML += `
  1825. <button onclick="showDistributionHistory(); closeModal('${modalId}');">查看分发记录</button>
  1826. `;
  1827. }
  1828. // 动态生成查看额外信息
  1829. if (userPermissions.includes('read_license')) {
  1830. modalContent.innerHTML += `
  1831. <button onclick="showExtraInfo(); closeModal('${modalId}');">查看额外信息</button>
  1832. `;
  1833. }
  1834. // 检查是否有 `update_license` 权限,决定是否显示修改信息按钮
  1835. if (userPermissions.includes('update_license')) {
  1836. modalContent.innerHTML += `<button onclick="modifyLicenseInfo(); closeModal('${modalId}');">修改信息</button>`;
  1837. }
  1838. // 检查是否有 `delete_license` 权限,决定是否显示删除按钮
  1839. if (userPermissions.includes('delete_license')) {
  1840. modalContent.innerHTML += `<button onclick="confirmDelete(); closeModal('${modalId}');">删除</button>`;
  1841. }
  1842. // 显示菜单位置
  1843. modalContent.style.top = `${event.clientY}px`;
  1844. modalContent.style.left = `${event.clientX}px`;
  1845. modal.style.display = 'block';
  1846. }
  1847. function closeModal(modalId) {
  1848. document.getElementById(modalId).style.display = 'none';
  1849. }
  1850. // function closeUserInfo() {
  1851. // document.getElementById('userModal').style.display = 'none';
  1852. // }
  1853. //删除一行lic信息
  1854. function confirmDelete() {
  1855. const confirmDeleteModal = document.getElementById('confirmDeleteModal');
  1856. confirmDeleteModal.innerHTML = `
  1857. <div class="centered-modal-content">
  1858. <span class="close" onclick="closeModal('confirmDeleteModal')" style="font-size: 24px; font-weight: bold; color: #555; cursor: pointer;">&times;</span>
  1859. <div style="margin-bottom: 15px; border: 1px solid #ddd; padding: 10px; border-radius: 10px;">
  1860. <p><strong>申请日期:</strong> ${selectedRowData.ApplicationDate}</p>
  1861. <p><strong>关联项目:</strong> ${selectedRowData.AssociatedProject}</p>
  1862. <p><strong>使用单位:</strong> ${selectedRowData.Company}</p>
  1863. </div>
  1864. <p>确认删除此行数据吗?</p>
  1865. <button class="flat-rounded-button" onclick="deleteRow()">确认</button>
  1866. <button class="flat-rounded-button" onclick="closeModal('confirmDeleteModal')">取消</button>
  1867. </div>
  1868. `;
  1869. confirmDeleteModal.style.display = 'block';
  1870. }
  1871. function deleteRow() {
  1872. fetch(`http://127.0.0.1:8080/api/admin/deleteLicRow`, {
  1873. method: 'POST',
  1874. headers: {
  1875. 'Authorization': `Bearer ${token}`,
  1876. 'Content-Type': 'application/json'
  1877. },
  1878. body: JSON.stringify({ uniqueID: selectedRowData.UniqueID })
  1879. }).then(response => {
  1880. if (response.ok) {
  1881. alert('删除成功');
  1882. closeModal('confirmDeleteModal');
  1883. // fetchApplications(LisOffset, pageSize);
  1884. const startOffset = currentOffset; // 当前的起始位置
  1885. const endOffset = startOffset + itemsPerPage - 1; // 计算结束位置
  1886. fetchApplications(startOffset, endOffset); // 传入计算好的起始和结束位置
  1887. } else {
  1888. alert('删除失败');
  1889. }
  1890. });
  1891. }
  1892. //添加用户
  1893. document.getElementById('addUserButton').addEventListener('click', function() {
  1894. document.getElementById('addUserModal').style.display = 'block';
  1895. });
  1896. //添加用户
  1897. function saveNewUser() {
  1898. const username = document.getElementById('addUsername').value.trim();
  1899. const password = document.getElementById('addPassword').value.trim();
  1900. const account = document.getElementById('addAccount').value.trim();
  1901. const telephone = document.getElementById('addTelephone').value.trim();
  1902. const email = document.getElementById('addEmail').value.trim();
  1903. // 验证每个字段都不能为空
  1904. if (!username || !password || !account || !telephone || !email) {
  1905. alert('有空选项未填写');
  1906. return;
  1907. }
  1908. // 验证电话是否为11位数字
  1909. const phonePattern = /^\d{11}$/;
  1910. if (!phonePattern.test(telephone)) {
  1911. alert('电话必须是11位数字');
  1912. return;
  1913. }
  1914. // 验证密码长度是否至少为6位
  1915. if (password.length < 6) {
  1916. alert('密码长度必须至少为6位');
  1917. return;
  1918. }
  1919. // 验证邮箱是否包含@符号
  1920. if (!email.includes('@')) {
  1921. alert('邮箱必须包含@符号');
  1922. return;
  1923. }
  1924. // 验证账号长度是否至少为3位
  1925. if (account.length < 3) {
  1926. alert('账号长度必须至少为3位');
  1927. return;
  1928. }
  1929. const newUser = {
  1930. Username: username,
  1931. Password: password,
  1932. Account: account,
  1933. Telephone: telephone,
  1934. Email: email
  1935. };
  1936. fetch('http://127.0.0.1:8080/api/register', { // 修改为实际的API路径
  1937. method: 'POST',
  1938. headers: {
  1939. 'Authorization': `Bearer ${token}`,
  1940. 'Content-Type': 'application/json'
  1941. },
  1942. body: JSON.stringify(newUser)
  1943. })
  1944. .then(response => response.json())
  1945. .then(data => {
  1946. if (data.success) {
  1947. alert('用户创建成功!');
  1948. fetchUsers(); // 重新加载用户列表
  1949. closeModal('addUserModal'); // 关闭模态框
  1950. } else {
  1951. alert('用户创建失败:' + data.error);
  1952. }
  1953. });
  1954. }
  1955. function deleteUser(uniqueID) {
  1956. fetch('http://127.0.0.1:8080/api/admin/deleteUser', {
  1957. method: 'POST',
  1958. headers: {
  1959. 'Authorization': `Bearer ${token}`,
  1960. 'Content-Type': 'application/json'
  1961. },
  1962. body: JSON.stringify({ UniqueID: uniqueID })
  1963. })
  1964. .then(response => response.json())
  1965. .then(data => {
  1966. if (data.success) {
  1967. alert('用户删除成功!');
  1968. fetchUsers(); // 重新加载用户列表
  1969. } else {
  1970. alert('用户删除失败:' + data.error);
  1971. }
  1972. })
  1973. .catch(error => {
  1974. console.error('Error deleting user:', error);
  1975. alert('删除用户时发生错误,请稍后再试。');
  1976. });
  1977. }
  1978. function confirmDeleteUser(uniqueID) {
  1979. const confirmed = confirm("确认删除此用户吗?");
  1980. if (confirmed) {
  1981. deleteUser(uniqueID);
  1982. }
  1983. }
  1984. // 分发模态框
  1985. function showEmailModal(supportEmail, salesEmail, uniqueID,oa_request_id) {
  1986. // 清空并设置默认值
  1987. document.getElementById('emailInputs').innerHTML = `
  1988. <div>
  1989. <input type="checkbox" id="supportEmailCheckbox" value="${supportEmail}" checked>
  1990. <label for="supportEmailCheckbox"> 运维邮箱: ${supportEmail}</label>
  1991. </div>
  1992. <div>
  1993. <input type="checkbox" id="salesEmailCheckbox" value="${salesEmail}" checked>
  1994. <label for="salesEmailCheckbox"> 销售邮箱: ${salesEmail}</label>
  1995. </div>
  1996. `;
  1997. document.getElementById('userInputs').innerHTML = ''; // 清空用户输入
  1998. // 获取用户信息并填充第一个用户输入框
  1999. fetch('http://127.0.0.1:8080/api/admin/distributeLicenseByUserInfo', {
  2000. method: 'GET',
  2001. headers: {
  2002. 'Authorization': `Bearer ${token}`,
  2003. 'Content-Type': 'application/json'
  2004. }
  2005. })
  2006. .then(response => response.json())
  2007. .then(data => {
  2008. const userSelect = document.createElement('select');
  2009. userSelect.id = 'userSelect1';
  2010. userSelect.className = 'email-modal-input';
  2011. data.data.forEach(user => {
  2012. userMap[user.Username] = {// 存储用户名和用户ID的映射
  2013. Account: user.Account,
  2014. UniqueID: user.UniqueID,
  2015. Username: user.Username,
  2016. Email: user.Email,
  2017. Role: user.Role,
  2018. Telephone:user.Telephone
  2019. };
  2020. const option = document.createElement('option');
  2021. option.value = user.Username;
  2022. option.textContent = user.Username;
  2023. userSelect.appendChild(option);
  2024. });
  2025. //document.getElementById('userInputs').appendChild(userSelect);
  2026. });
  2027. document.getElementById('emailModal').style.display = 'block';
  2028. selectedRowData = { ...selectedRowData, UniqueID: uniqueID ,Oa_request_id: oa_request_id};
  2029. }
  2030. function addEmailInput() {
  2031. const emailInputs = document.getElementById('emailInputs');
  2032. const newInputDiv = document.createElement('div');
  2033. newInputDiv.style.display = 'flex';
  2034. newInputDiv.style.alignItems = 'center';
  2035. newInputDiv.style.marginBottom = '10px';
  2036. const newInput = document.createElement('input');
  2037. newInput.type = 'text';
  2038. newInput.className = 'email-modal-input';
  2039. newInput.style.flexGrow = '1';
  2040. newInputDiv.appendChild(newInput);
  2041. const deleteButton = document.createElement('button');
  2042. deleteButton.textContent = '✕';
  2043. deleteButton.style.background = 'none';
  2044. deleteButton.style.border = 'none';
  2045. deleteButton.style.color = '#007aff';
  2046. deleteButton.style.cursor = 'pointer';
  2047. deleteButton.style.fontSize = '12px'; /* 再次缩小字体大小 */
  2048. deleteButton.style.padding = '0'; /* 移除内边距 */
  2049. deleteButton.style.marginLeft = '3px'; /* 减少与输入框的间距 */
  2050. deleteButton.style.width = '20px'; /* 限制按钮宽度 */
  2051. deleteButton.style.height = '20px'; /* 限制按钮高度 */
  2052. deleteButton.onclick = () => {
  2053. newInputDiv.remove();
  2054. };
  2055. newInputDiv.appendChild(deleteButton);
  2056. emailInputs.appendChild(newInputDiv);
  2057. }
  2058. function addUserInput() {
  2059. const userInputs = document.getElementById('userInputs');
  2060. const newUserDiv = document.createElement('div');
  2061. newUserDiv.className = 'user-select-container';
  2062. newUserDiv.style.display = 'flex';
  2063. newUserDiv.style.alignItems = 'center';
  2064. newUserDiv.style.marginBottom = '10px';
  2065. const newUserSelect = document.createElement('select');
  2066. newUserSelect.className = 'email-modal-input';
  2067. newUserSelect.style.flexGrow = '1';
  2068. newUserSelect.style.marginRight = '5px';
  2069. // 添加一个默认的空白选项
  2070. const defaultOption = document.createElement('option');
  2071. defaultOption.value = '';
  2072. defaultOption.textContent = '请选择用户';
  2073. newUserSelect.appendChild(defaultOption);
  2074. // 获取当前已选择的用户
  2075. const selectedValues = Array.from(document.querySelectorAll('.user-select-container select'))
  2076. .map(select => select.value);
  2077. // 获取用户列表并填充到选择框中
  2078. fetch('http://127.0.0.1:8080/api/admin/distributeLicenseByUserInfo', {
  2079. method: 'GET',
  2080. headers: {
  2081. 'Authorization': `Bearer ${token}`,
  2082. 'Content-Type': 'application/json'
  2083. }
  2084. })
  2085. .then(response => response.json())
  2086. .then(data => {
  2087. data.data.forEach(user => {
  2088. // 仅显示未被选中的用户,并且过滤掉admin用户
  2089. if (!selectedValues.includes(user.Username) && user.Username !== 'admin') {
  2090. const option = document.createElement('option');
  2091. option.value = user.Username;
  2092. option.textContent = user.Username;
  2093. newUserSelect.appendChild(option);
  2094. }
  2095. });
  2096. });
  2097. const deleteButton = document.createElement('button');
  2098. deleteButton.textContent = '✕';
  2099. deleteButton.style.background = 'none';
  2100. deleteButton.style.border = 'none';
  2101. deleteButton.style.color = '#007aff';
  2102. deleteButton.style.cursor = 'pointer';
  2103. deleteButton.style.fontSize = '12px';
  2104. deleteButton.style.padding = '0';
  2105. deleteButton.style.marginLeft = '3px';
  2106. deleteButton.style.width = '20px';
  2107. deleteButton.style.height = '20px';
  2108. deleteButton.onclick = () => {
  2109. newUserDiv.remove();
  2110. updateUserOptions(); // 更新其他下拉框中的选项
  2111. };
  2112. newUserSelect.addEventListener('change', updateUserOptions);
  2113. newUserDiv.appendChild(newUserSelect);
  2114. newUserDiv.appendChild(deleteButton);
  2115. userInputs.appendChild(newUserDiv);
  2116. // 设置空白选项为默认选项
  2117. newUserSelect.selectedIndex = 0;
  2118. }
  2119. function updateUserOptions() {
  2120. const selectedValues = Array.from(document.querySelectorAll('.user-select-container select'))
  2121. .map(select => select.value);
  2122. document.querySelectorAll('.user-select-container select').forEach(select => {
  2123. const currentValue = select.value;
  2124. select.innerHTML = ''; // 清空现有选项
  2125. // 添加一个默认的空白选项
  2126. const defaultOption = document.createElement('option');
  2127. defaultOption.value = '';
  2128. defaultOption.textContent = '请选择用户';
  2129. select.appendChild(defaultOption);
  2130. fetch('http://127.0.0.1:8080/api/admin/userInfoAll', {
  2131. method: 'GET',
  2132. headers: {
  2133. 'Authorization': `Bearer ${token}`,
  2134. 'Content-Type': 'application/json'
  2135. }
  2136. })
  2137. .then(response => response.json())
  2138. .then(data => {
  2139. data.data.forEach(user => {
  2140. if (!selectedValues.includes(user.Username) || user.Username === currentValue) {
  2141. if (user.Username !== 'admin') { // 过滤掉admin用户
  2142. const option = document.createElement('option');
  2143. option.value = user.Username;
  2144. option.textContent = user.Username;
  2145. select.appendChild(option);
  2146. }
  2147. }
  2148. });
  2149. select.value = currentValue;
  2150. });
  2151. });
  2152. }
  2153. // 打开修改信息表单框
  2154. function modifyLicenseInfo() {
  2155. const form = document.getElementById('modifyLicenseForm');
  2156. // 将选中的行数据填充到表单中
  2157. form.creator.value = selectedRowData.Creator;
  2158. form.applicationDate.value = selectedRowData.ApplicationDate;
  2159. form.associatedProject.value = selectedRowData.GlxmName;
  2160. form.salesPerson.value = selectedRowData.SalesPerson;
  2161. form.salesEmail.value = selectedRowData.SalesEmail;
  2162. form.supportPerson.value = selectedRowData.SupportPerson;
  2163. form.supportEmail.value = selectedRowData.SupportEmail;
  2164. form.totalNodes.value = selectedRowData.TotalNodes;
  2165. form.company.value = selectedRowData.Company;
  2166. form.productName.value = selectedRowData.ProductName;
  2167. form.version.value = selectedRowData.ProductVersion;
  2168. form.nodeCount.value = selectedRowData.NodeCount;
  2169. document.getElementById('modifyLicenseModal').style.display = 'block';
  2170. }
  2171. // 保存修改后的数据
  2172. function saveLicenseChanges() {
  2173. const form = document.getElementById('modifyLicenseForm');
  2174. const updatedData = {
  2175. UniqueID: selectedRowData.UniqueID,
  2176. Creator: form.creator.value,
  2177. ApplicationDate: form.applicationDate.value,
  2178. AssociatedProject: form.associatedProject.value,
  2179. SalesPerson: form.salesPerson.value,
  2180. SalesEmail: form.salesEmail.value,
  2181. SupportPerson: form.supportPerson.value,
  2182. SupportEmail: form.supportEmail.value,
  2183. TotalNodes: parseInt(form.totalNodes.value, 10), // 将 TotalNodes 转换为整数
  2184. Company: form.company.value,
  2185. ProductName: form.productName.value,
  2186. Version: form.version.value,
  2187. NodeCount: parseInt(form.nodeCount.value, 10), // 将 NodeCount 转换为整数
  2188. };
  2189. fetch(`http://127.0.0.1:8080/api/admin/UpdateLicense`, {
  2190. method: 'POST',
  2191. headers: {
  2192. 'Authorization': `Bearer ${token}`,
  2193. 'Content-Type': 'application/json'
  2194. },
  2195. body: JSON.stringify(updatedData)
  2196. })
  2197. .then(response => response.json())
  2198. .then(data => {
  2199. if (data.success) {
  2200. alert('License信息更新成功!');
  2201. // fetchApplications(LisOffset, pageSize);
  2202. const startOffset = currentOffset; // 当前的起始位置
  2203. const endOffset = startOffset + itemsPerPage - 1; // 计算结束位置
  2204. fetchApplications(startOffset, endOffset); // 传入计算好的起始和结束位置
  2205. closeModal('modifyLicenseModal');
  2206. } else {
  2207. alert('License信息更新失败:' + data.error);
  2208. }
  2209. });
  2210. }
  2211. function updateUserOptions() {
  2212. const selectedValues = Array.from(document.querySelectorAll('.user-select-container select'))
  2213. .map(select => select.value);
  2214. document.querySelectorAll('.user-select-container select').forEach(select => {
  2215. const currentValue = select.value; // 保留当前选择值
  2216. select.innerHTML = ''; // 清空现有选项
  2217. fetch('http://127.0.0.1:8080/api/admin/distributeLicenseByUserInfo', {
  2218. method: 'GET',
  2219. headers: {
  2220. 'Authorization': `Bearer ${token}`,
  2221. 'Content-Type': 'application/json'
  2222. }
  2223. })
  2224. .then(response => response.json())
  2225. .then(data => {
  2226. data.data.forEach(user => {
  2227. // 保留当前值,并排除已经在其他下拉框中选中的值
  2228. if (!selectedValues.includes(user.Username) || user.Username === currentValue) {
  2229. const option = document.createElement('option');
  2230. option.value = user.Username;
  2231. option.textContent = user.Username;
  2232. if (user.Username === currentValue) {
  2233. option.selected = true; // 保持当前选择
  2234. }
  2235. select.appendChild(option);
  2236. }
  2237. });
  2238. });
  2239. });
  2240. }
  2241. //lic分发给用户 与邮件
  2242. function sendEmail() {
  2243. console.log('Send button clicked');
  2244. const emailInputs = document.querySelectorAll('.email-modal-input[type="text"]');
  2245. let emails = Array.from(emailInputs)
  2246. .map(input => input.value.trim())
  2247. .filter(email => email && email.includes('@'))
  2248. .join(',');
  2249. const supportEmailChecked = document.getElementById('supportEmailCheckbox').checked;
  2250. const salesEmailChecked = document.getElementById('salesEmailCheckbox').checked;
  2251. const emailArray = emails ? [emails] : [];
  2252. if (supportEmailChecked) {
  2253. emailArray.push(document.getElementById('supportEmailCheckbox').value);
  2254. }
  2255. if (salesEmailChecked) {
  2256. emailArray.push(document.getElementById('salesEmailCheckbox').value);
  2257. }
  2258. emails = emailArray.join(',');
  2259. // if (!emails) {
  2260. // alert('请至少选择一个邮箱地址。');
  2261. // return;
  2262. // }
  2263. console.log('Emails to send:', emails);
  2264. const userInputs = document.querySelectorAll('select.email-modal-input');
  2265. console.log('userMap:', userMap);
  2266. const users = Array.from(userInputs)
  2267. .map(select => userMap[select.value].Account)
  2268. .join(',');
  2269. const userIds = Array.from(userInputs)
  2270. .map(select => userMap[select.value].UniqueID)
  2271. .join(',');
  2272. const userNames = Array.from(userInputs)
  2273. .map(select => userMap[select.value].Username);
  2274. const operatorUniqueID = userMap[currentUserName].UniqueID;
  2275. console.log('User IDs:', userIds);
  2276. console.log('Users:', users);
  2277. console.log(' selectedRowData.UniqueID:', selectedRowData.UniqueID);
  2278. if (!userIds) {
  2279. alert('请至少选择一个用户。');
  2280. return;
  2281. }
  2282. const requestData = {
  2283. LicenseUniqueID: selectedRowData.UniqueID,
  2284. Oa_request_id: selectedRowData.Oa_request_id,
  2285. UserUniqueIDs: userIds.split(','),
  2286. UserAccounts: users.split(','),
  2287. Emails: emails,
  2288. UserNames: userNames,
  2289. OperatorUniqueID: operatorUniqueID
  2290. };
  2291. console.log('requestData:', requestData);
  2292. fetch('http://127.0.0.1:8080/api/admin/distributeLicense', {
  2293. method: 'POST',
  2294. headers: {
  2295. 'Authorization': `Bearer ${token}`,
  2296. 'Content-Type': 'application/json'
  2297. },
  2298. body: JSON.stringify(requestData)
  2299. })
  2300. .then(response => {
  2301. console.log('Response received');
  2302. return response.json();
  2303. })
  2304. .then(data => {
  2305. if (data.success) {
  2306. alert('分发成功!');
  2307. closeModal('emailModal');
  2308. } else {
  2309. // 检查是否有 error 字段,并提示用户详细的错误信息
  2310. const errorMessage = data.error || '分发失败。';
  2311. alert(`分发失败: ${errorMessage}`);
  2312. }
  2313. })
  2314. .catch(error => {
  2315. console.error('Error occurred during email distribution:', error);
  2316. alert('分发失败,请检查网络或后端服务。');
  2317. });
  2318. }
  2319. function showDistributionHistory() {
  2320. fetch('http://127.0.0.1:8080/api/admin/GetlicenseRecord', {
  2321. method: 'POST',
  2322. headers: {
  2323. 'Authorization': `Bearer ${token}`,
  2324. 'Content-Type': 'application/json'
  2325. },
  2326. body: JSON.stringify({ uniqueID: selectedRowData.UniqueID, oa_request_id: selectedRowData.oa_request_id })
  2327. })
  2328. .then(response => response.json())
  2329. .then(data => {
  2330. const distributionHistoryContent = document.getElementById('distributionHistoryContent');
  2331. const { license_record_to_user, license_record_to_emails } = data.data;
  2332. // 确保 license_record_to_user 和 license_record_to_emails 存在并且是数组
  2333. const userRecords = Array.isArray(license_record_to_user) ? license_record_to_user : [];
  2334. const emailRecords = Array.isArray(license_record_to_emails) ? license_record_to_emails : [];
  2335. if (userRecords.length > 0 || emailRecords.length > 0) {
  2336. const userHistoryHtml = userRecords.map(record => `
  2337. <div style="margin-bottom: 20px; padding: 10px; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;">
  2338. <p><strong>已转发给用户:</strong> ${record.user_account}</p>
  2339. <p><strong>分发时间:</strong> ${new Date(record.up_time).toLocaleString()}</p>
  2340. </div>
  2341. `).join('');
  2342. const emailHistoryHtml = emailRecords.map(record => `
  2343. <div style="margin-bottom: 20px; padding: 10px; border: 1px solid #ddd; border-radius: 10px; background-color: #f9f9f9;">
  2344. <p><strong>已发给邮箱:</strong> ${record.emails}</p>
  2345. <p><strong>分发时间:</strong> ${new Date(record.up_time).toLocaleString()}</p>
  2346. </div>
  2347. `).join('');
  2348. distributionHistoryContent.innerHTML = userHistoryHtml + emailHistoryHtml;
  2349. } else {
  2350. distributionHistoryContent.innerHTML = `<p>没有分发历史记录。</p>`;
  2351. }
  2352. // 显示模态框
  2353. const distributionHistoryModal = document.getElementById('distributionHistoryModal');
  2354. distributionHistoryModal.style.display = 'block';
  2355. });
  2356. }
  2357. function showMoreUserInfo() {
  2358. const extraInfoContent = document.getElementById('extraInfoContent');
  2359. extraInfoContent.innerHTML = `
  2360. <p><strong>用户名:</strong> ${selectedRowData.Username}</p>
  2361. <p><strong>电话:</strong> ${selectedRowData.Telephone}</p>
  2362. <p><strong>邮箱:</strong> ${selectedRowData.Email}</p>
  2363. <p><strong>权限:</strong> ${selectedRowData.Role}</p>
  2364. `;
  2365. document.getElementById('extraInfoModal').style.display = 'block';
  2366. }
  2367. function modifyUser() {
  2368. const userInfoContent = document.getElementById('extraInfoContent');
  2369. userInfoContent.innerHTML = `
  2370. <p><strong>用户名:</strong> ${selectedRowData.Username}</p>
  2371. <p><strong>电话:</strong> ${selectedRowData.Telephone}</p>
  2372. <p><strong>邮箱:</strong> ${selectedRowData.Email}</p>
  2373. <p><strong>权限:</strong> ${selectedRowData.Role}</p>
  2374. <button onclick="showEditUserForm()">编辑用户信息</button>
  2375. `;
  2376. document.getElementById('extraInfoModal').style.display = 'block';
  2377. }
  2378. //查看额外信息
  2379. function showExtraInfo() {
  2380. const extraInfoContent = document.getElementById('extraInfoContent');
  2381. // 清空之前的内容
  2382. extraInfoContent.innerHTML = '';
  2383. // 使用预定义的字段名和中文翻译
  2384. const fieldTranslations = {
  2385. id: "ID",
  2386. user_id: "用户ID",
  2387. up_user: "上传用户",
  2388. up_time: "上传时间",
  2389. del_time: "删除时间",
  2390. License1: "License 1",
  2391. License2: "License 2",
  2392. LicenseFlage: "License 状态",
  2393. UniqueID: "唯一标识符",
  2394. Creator: "创建人",
  2395. ApplicationDate: "申请日期",
  2396. AssociatedProject: "关联项目",
  2397. SalesPerson: "销售人员",
  2398. SalesEmail: "销售邮箱",
  2399. SupportPerson: "支持人员",
  2400. SupportEmail: "支持邮箱",
  2401. TotalNodes: "总节点数",
  2402. Company: "公司",
  2403. ProductName: "产品名称",
  2404. Version: "版本",
  2405. NodeCount: "节点数",
  2406. Processor: "处理器",
  2407. OperatingSystem: "操作系统",
  2408. MasterMacAddress: "主MAC地址",
  2409. SecondaryMasterMacAddress: "备用主MAC地址"
  2410. };
  2411. // 使用指定的字段进行展示
  2412. const fieldsToShow = [
  2413. "id", "user_id", "up_user", "up_time", "del_time", "License1", "License2",
  2414. "LicenseFlage", "UniqueID", "Creator", "ApplicationDate", "AssociatedProject",
  2415. "SalesPerson", "SalesEmail", "SupportPerson", "SupportEmail", "TotalNodes",
  2416. "Company", "ProductName", "Version", "NodeCount", "Processor", "OperatingSystem",
  2417. "MasterMacAddress", "SecondaryMasterMacAddress"
  2418. ];
  2419. fieldsToShow.forEach(key => {
  2420. if (selectedRowData.hasOwnProperty(key)) {
  2421. let value = selectedRowData[key];
  2422. // 特殊处理 up_time 和 del_time
  2423. if (key === 'up_time' || key === 'del_time') {
  2424. if (value.Valid) {
  2425. value = new Date(value.Time).toLocaleString(); // 格式化日期时间
  2426. } else {
  2427. value = '无';
  2428. }
  2429. }
  2430. // 处理 License1 和 License2,提取字符串字段
  2431. if (key === 'License1' || key === 'License2') {
  2432. // 假设 License 对象包含一个名为 'Details' 的字符串字段
  2433. value = value.String || '[无数据]';
  2434. }
  2435. // 处理 MasterMacAddress 和 SecondaryMasterMacAddress,提取字符串字段
  2436. // if (key === 'MasterMacAddress' || key === 'SecondaryMasterMacAddress') {
  2437. // // 假设 License 对象包含一个名为 'Details' 的字符串字段
  2438. // value = value.String || '[无数据]';
  2439. // }
  2440. const infoElement = document.createElement('p');
  2441. infoElement.innerHTML = `<strong>${fieldTranslations[key]}:</strong> ${value}`;
  2442. extraInfoContent.appendChild(infoElement);
  2443. }
  2444. });
  2445. // 显示 modal
  2446. document.getElementById('extraInfoModal').style.display = 'block';
  2447. }
  2448. function showRoleManagement() {
  2449. document.getElementById('table-container').style.display = 'none';
  2450. document.getElementById('user-management').style.display = 'none'; // 隐藏用户管理页面
  2451. document.getElementById('role-management').style.display = 'block';;
  2452. fetchRoles();
  2453. }
  2454. function fetchRoles() {
  2455. fetch('http://127.0.0.1:8080/api/admin/GetRoles', {
  2456. method: 'POST',
  2457. headers: {
  2458. 'Authorization': `Bearer ${token}`,
  2459. 'Content-Type': 'application/json'
  2460. },
  2461. body: JSON.stringify({ Name: " " }) // 发送空的 Name 参数
  2462. })
  2463. .then(response => response.json())
  2464. .then(data => {
  2465. const roleContainer = document.getElementById('roles-container');
  2466. roleContainer.innerHTML = ''; // 清空之前的内容
  2467. const permissionMap = {
  2468. 'generate_license': '生成许可证',
  2469. 'upload_license': '上传许可证',
  2470. 'read_license': '读取许可证',
  2471. 'read_license_record': '读取许可证分发记录',
  2472. 'update_license': '修改许可证',
  2473. 'delete_license': '删除许可证',
  2474. 'dispat_license': '分发许可证',
  2475. 'create_user': '创建用户',
  2476. 'read_user': '读取用户',
  2477. 'update_user': '更新用户',
  2478. 'delete_user': '删除用户',
  2479. 'create_role': '创建角色',
  2480. 'delete_role': '删除角色',
  2481. 'update_role': '更新角色',
  2482. 'get_role': '获取角色'
  2483. };
  2484. // 检查用户是否有 create_role 权限
  2485. const hasCreateRolePermission = userPermissions.includes('create_role');
  2486. // 如果有权限则显示“创建角色”按钮
  2487. if (hasCreateRolePermission) {
  2488. document.getElementById('createRoleButton').style.display = 'block';
  2489. } else {
  2490. document.getElementById('createRoleButton').style.display = 'none';
  2491. }
  2492. // 处理置顶角色和其他角色的渲染(代码不变)
  2493. const topRoles = ['admin', 'guest', 'supportRole'];
  2494. topRoles.forEach(role => {
  2495. if (data.data[role]) {
  2496. renderRole(roleContainer, data.data[role], permissionMap, true);
  2497. }
  2498. });
  2499. Object.keys(data.data).forEach(role => {
  2500. if (!topRoles.includes(role)) {
  2501. renderRole(roleContainer, data.data[role], permissionMap, false);
  2502. }
  2503. });
  2504. });
  2505. }
  2506. function renderRole(container, roleInfo, permissionMap, isTopRole) {
  2507. const roleDiv = document.createElement('div');
  2508. roleDiv.className = 'role-item';
  2509. roleDiv.style.position = 'relative'; // 确保弹出菜单能够正确定位
  2510. if (isTopRole) {
  2511. roleDiv.classList.add('top-role'); // 应用置顶角色的样式
  2512. }
  2513. let permissions = roleInfo.Permissions.map(permission => permissionMap[permission]);
  2514. let permissionsHtml = permissions.join(','); // 使用逗号分隔并合并为一行
  2515. roleDiv.innerHTML = `
  2516. <h3>${roleInfo.Name}</h3>
  2517. <p>${permissionsHtml}</p>
  2518. `;
  2519. container.appendChild(roleDiv);
  2520. // 添加事件监听器,处理点击和右键点击弹出菜单
  2521. roleDiv.addEventListener('click', function(event) {
  2522. event.stopPropagation(); // 阻止事件冒泡
  2523. event.preventDefault(); // 阻止默认行为
  2524. showRoleActionMenu(event, roleInfo.Name);
  2525. });
  2526. roleDiv.addEventListener('contextmenu', function(event) {
  2527. event.preventDefault();
  2528. showRoleActionMenu(event, roleInfo.Name);
  2529. });
  2530. }
  2531. function showRoleActionMenu(event, roleName) {
  2532. const existingMenu = document.getElementById('role-action-menu');
  2533. if (existingMenu) {
  2534. existingMenu.remove();
  2535. }
  2536. const menu = document.createElement('div');
  2537. menu.id = 'role-action-menu';
  2538. menu.style.position = 'absolute';
  2539. menu.style.top = `${event.clientY}px`;
  2540. menu.style.left = `${event.clientX}px`;
  2541. menu.style.backgroundColor = '#fff';
  2542. menu.style.border = '1px solid #ccc';
  2543. menu.style.borderRadius = '5px';
  2544. menu.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.2)';
  2545. menu.style.padding = '10px';
  2546. menu.style.zIndex = '1000';
  2547. const topRoles = ['admin', 'guest', 'support'];
  2548. if (topRoles.includes(roleName)) {
  2549. // 为 admin, guest, supportRole 设置灰色和不可点击样式
  2550. const disabledButton = document.createElement('button');
  2551. disabledButton.textContent = '不可操作';
  2552. disabledButton.style.display = 'block';
  2553. disabledButton.style.width = '100%';
  2554. disabledButton.style.padding = '10px 20px';
  2555. disabledButton.style.border = 'none';
  2556. disabledButton.style.borderRadius = '15px';
  2557. disabledButton.style.cursor = 'not-allowed';
  2558. disabledButton.style.backgroundColor = '#d3d3d3'; // 灰色背景
  2559. disabledButton.style.color = '#999'; // 灰色文字
  2560. menu.appendChild(disabledButton);
  2561. } else {
  2562. // 检查用户是否有 update_role 和 delete_role 权限
  2563. const hasUpdateRolePermission = userPermissions.includes('update_role');
  2564. const hasDeleteRolePermission = userPermissions.includes('delete_role');
  2565. // 创建和添加修改角色按钮
  2566. if (hasUpdateRolePermission) {
  2567. const modifyButton = document.createElement('button');
  2568. modifyButton.textContent = '修改角色';
  2569. modifyButton.style.display = 'block';
  2570. modifyButton.style.marginBottom = '10px';
  2571. modifyButton.style.width = '100%';
  2572. modifyButton.style.padding = '10px 20px';
  2573. modifyButton.style.border = 'none';
  2574. modifyButton.style.borderRadius = '15px';
  2575. modifyButton.style.cursor = 'pointer';
  2576. modifyButton.style.transition = 'background-color 0.3s, color 0.3s';
  2577. modifyButton.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.1)';
  2578. modifyButton.style.backgroundColor = '#007aff';
  2579. modifyButton.style.color = '#fff';
  2580. modifyButton.addEventListener('mouseenter', function () {
  2581. modifyButton.style.backgroundColor = '#005bb5';
  2582. });
  2583. modifyButton.addEventListener('mouseleave', function () {
  2584. modifyButton.style.backgroundColor = '#007aff';
  2585. });
  2586. modifyButton.addEventListener('click', function () {
  2587. modifyRole(roleName);
  2588. menu.remove(); // 点击按钮后,关闭菜单栏
  2589. });
  2590. menu.appendChild(modifyButton);
  2591. }
  2592. // 创建和添加删除角色按钮
  2593. if (hasDeleteRolePermission) {
  2594. const deleteButton = document.createElement('button');
  2595. deleteButton.textContent = '删除角色';
  2596. deleteButton.style.display = 'block';
  2597. deleteButton.style.width = '100%';
  2598. deleteButton.style.padding = '10px 20px';
  2599. deleteButton.style.border = 'none';
  2600. deleteButton.style.borderRadius = '15px';
  2601. deleteButton.style.cursor = 'pointer';
  2602. deleteButton.style.transition = 'background-color 0.3s, color 0.3s';
  2603. deleteButton.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.1)';
  2604. deleteButton.style.backgroundColor = '#ff3b30';
  2605. deleteButton.style.color = '#fff';
  2606. deleteButton.addEventListener('mouseenter', function () {
  2607. deleteButton.style.backgroundColor = '#c23321';
  2608. });
  2609. deleteButton.addEventListener('mouseleave', function () {
  2610. deleteButton.style.backgroundColor = '#ff3b30';
  2611. });
  2612. deleteButton.addEventListener('click', function () {
  2613. deleteRole(roleName);
  2614. menu.remove(); // 点击按钮后,关闭菜单栏
  2615. });
  2616. menu.appendChild(deleteButton);
  2617. }
  2618. // 如果用户没有修改或删除权限,则显示没有选项的提示
  2619. if (!hasUpdateRolePermission && !hasDeleteRolePermission) {
  2620. const noOption = document.createElement('div');
  2621. noOption.textContent = '没有可用的操作';
  2622. noOption.style.textAlign = 'center';
  2623. noOption.style.color = '#999';
  2624. menu.appendChild(noOption);
  2625. }
  2626. }
  2627. document.body.appendChild(menu);
  2628. document.addEventListener('click', function closeMenu(event) {
  2629. if (!menu.contains(event.target)) {
  2630. menu.remove();
  2631. document.removeEventListener('click', closeMenu);
  2632. }
  2633. });
  2634. }
  2635. //修改角色信息
  2636. function modifyRole(roleName) {
  2637. console.log(`modifyRole called with roleName: ${roleName}`);
  2638. fetchRoleInfo(roleName, function(roleInfo) {
  2639. console.log(`fetchRoleInfo returned:`, roleInfo);
  2640. if (!roleInfo) {
  2641. console.error('Role info is undefined or null');
  2642. return;
  2643. }
  2644. const extraInfoContent = document.getElementById('extraInfoContent');
  2645. if (!extraInfoContent) {
  2646. console.error('Element with id "extraInfoContent" not found');
  2647. return;
  2648. }
  2649. extraInfoContent.innerHTML = `
  2650. <h3>修改角色: ${roleInfo.Name}</h3>
  2651. <label for="roleName">角色名称:</label>
  2652. <input type="text" id="roleName" value="${roleInfo.Name}" required><br><br>
  2653. <label for="permissions">权限:</label><br>
  2654. <div id="permissions">
  2655. <div>
  2656. <input type="checkbox" id="license" name="permissions" value="license" onchange="toggleSubPermissions('license', this)">
  2657. <label for="license">许可证</label>
  2658. <div id="licenseSubPermissions" style="margin-left: 20px;">
  2659. <input type="checkbox" id="generate_license" name="permissions" value="generate_license">
  2660. <label for="generate_license">生成许可证</label><br>
  2661. <input type="checkbox" id="upload_license" name="permissions" value="upload_license">
  2662. <label for="upload_license">上传许可证</label><br>
  2663. <input type="checkbox" id="read_license" name="permissions" value="read_license">
  2664. <label for="read_license">读取许可证</label><br>
  2665. <input type="checkbox" id="update_license" name="permissions" value="update_license">
  2666. <label for="update_license">更新许可证</label><br>
  2667. <input type="checkbox" id="delete_license" name="permissions" value="delete_license">
  2668. <label for="delete_license">删除许可证</label><br>
  2669. </div>
  2670. </div>
  2671. <div>
  2672. <input type="checkbox" id="user" name="permissions" value="user" onchange="toggleSubPermissions('user', this)">
  2673. <label for="user">用户</label>
  2674. <div id="userSubPermissions" style="margin-left: 20px;">
  2675. <input type="checkbox" id="create_user" name="permissions" value="create_user">
  2676. <label for="create_user">创建用户</label><br>
  2677. <input type="checkbox" id="read_user" name="permissions" value="read_user">
  2678. <label for="read_user">读取用户</label><br>
  2679. <input type="checkbox" id="update_user" name="permissions" value="update_user">
  2680. <label for="update_user">更新用户</label><br>
  2681. <input type="checkbox" id="delete_user" name="permissions" value="delete_user">
  2682. <label for="delete_user">删除用户</label><br>
  2683. </div>
  2684. </div>
  2685. <div>
  2686. <input type="checkbox" id="role" name="permissions" value="role" onchange="toggleSubPermissions('role', this)">
  2687. <label for="role">角色</label>
  2688. <div id="roleSubPermissions" style="margin-left: 20px;">
  2689. <input type="checkbox" id="create_role" name="permissions" value="create_role">
  2690. <label for="create_role">创建角色</label><br>
  2691. <input type="checkbox" id="delete_role" name="permissions" value="delete_role">
  2692. <label for="delete_role">删除角色</label><br>
  2693. <input type="checkbox" id="update_role" name="permissions" value="update_role">
  2694. <label for="update_role">更新角色</label><br>
  2695. <input type="checkbox" id="get_role" name="permissions" value="get_role">
  2696. <label for="get_role">获取角色</label><br>
  2697. </div>
  2698. </div>
  2699. </div><br><br>
  2700. <button onclick="saveRoleChanges('${roleInfo.Id}')">保存</button>
  2701. `;
  2702. console.log('Form content added to extraInfoContent');
  2703. const checkboxes = document.querySelectorAll('#permissions input[type="checkbox"]');
  2704. // 遍历所有复选框
  2705. checkboxes.forEach(checkbox => {
  2706. if (roleInfo.Permissions.includes(checkbox.value)) {
  2707. checkbox.checked = true; // 如果当前权限在roleInfo.Permissions中,则勾选
  2708. }
  2709. });
  2710. const extraInfoModal = document.getElementById('extraInfoModal');
  2711. if (!extraInfoModal) {
  2712. console.error('Element with id "extraInfoModal" not found');
  2713. return;
  2714. }
  2715. extraInfoModal.style.display = 'block'; // 强制显示模态框
  2716. console.log('Modal should be visible now');
  2717. });
  2718. }
  2719. function getCheckboxOptions(selectedPermissions) {
  2720. const permissionMap = {
  2721. 'generate_license': '生成许可证',
  2722. 'upload_license': '上传许可证',
  2723. 'read_license': '读取许可证',
  2724. 'update_license': '修改许可证',
  2725. 'delete_license': '删除许可证',
  2726. 'dispat_license': '分发许可证',
  2727. 'read_license_record': '读取许可证分发记录',
  2728. // 'get_user_info': '获取用户信息',
  2729. 'create_user': '创建用户',
  2730. 'read_user': '读取用户',
  2731. 'update_user': '更新用户',
  2732. 'delete_user': '删除用户',
  2733. 'create_role': '创建角色',
  2734. 'delete_role': '删除角色',
  2735. 'update_role': '更新角色',
  2736. 'get_role': '获取角色'
  2737. };
  2738. return Object.keys(permissionMap).map(permission => `
  2739. <div>
  2740. <input type="checkbox" id="${permission}" name="permissions" value="${permission}" ${selectedPermissions.includes(permission) ? 'checked' : ''}>
  2741. <label for="${permission}">${permissionMap[permission]}</label>
  2742. </div>
  2743. `).join('');
  2744. }
  2745. function fetchRoleInfo(roleName, callback) {
  2746. console.log(`fetchRoleInfo called with roleName: ${roleName}`);
  2747. fetch('http://127.0.0.1:8080/api/admin/GetRoles', {
  2748. method: 'POST',
  2749. headers: {
  2750. 'Authorization': `Bearer ${token}`,
  2751. 'Content-Type': 'application/json'
  2752. },
  2753. body: JSON.stringify({ Name: roleName })
  2754. })
  2755. .then(response => {
  2756. console.log('fetchRoleInfo response received', response);
  2757. return response.json();
  2758. })
  2759. .then(data => {
  2760. console.log('fetchRoleInfo data received', data);
  2761. // 直接从 data.data 获取角色信息
  2762. if (data && data.data) {
  2763. console.log('Role info found:', data.data);
  2764. callback(data.data); // 直接返回 data.data 而不是 data.data[roleName]
  2765. } else {
  2766. console.error('Role not found or unexpected data structure', data);
  2767. callback(null); // 如果角色信息未找到,返回 null
  2768. }
  2769. })
  2770. .catch(error => {
  2771. console.error('Error in fetchRoleInfo:', error);
  2772. callback(null); // 捕获异常情况
  2773. });
  2774. }
  2775. function getPermissionsOptions(selectedPermissions) {
  2776. const permissionMap = {
  2777. 'generate_license': '生成许可证',
  2778. 'upload_license': '上传许可证',
  2779. 'read_license': '读取许可证',
  2780. 'update_license': '修改许可证',
  2781. 'delete_license': '删除许可证',
  2782. 'dispat_license': '分发许可证',
  2783. 'read_license_record': '读取许可证分发记录',
  2784. //'get_user_info': '获取用户信息',
  2785. 'create_user': '创建用户',
  2786. 'read_user': '读取用户',
  2787. 'update_user': '更新用户',
  2788. 'delete_user': '删除用户',
  2789. 'create_role': '创建角色',
  2790. 'delete_role': '删除角色',
  2791. 'update_role': '更新角色',
  2792. 'get_role': '获取角色'
  2793. };
  2794. return Object.keys(permissionMap).map(permission => `
  2795. <option value="${permission}" ${selectedPermissions.includes(permission) ? 'selected' : ''}>
  2796. ${permissionMap[permission]}
  2797. </option>
  2798. `).join('');
  2799. }
  2800. function saveRoleChanges(roleId) {
  2801. const updatedRoleName = document.getElementById('roleName').value.trim();
  2802. const selectedPermissions = Array.from(document.querySelectorAll('#permissions input[type="checkbox"]:checked'))
  2803. .map(checkbox => checkbox.value)
  2804. .filter(value => !['license', 'user', 'role'].includes(value)); // 过滤掉一级分类
  2805. if (!updatedRoleName) {
  2806. alert('角色名称不能为空!');
  2807. return;
  2808. }
  2809. const updateRole = {
  2810. Id: parseInt(roleId, 10), // 确保 roleId 被传递并转换为整数
  2811. Name: updatedRoleName,
  2812. Permissions: selectedPermissions
  2813. };
  2814. fetch('http://127.0.0.1:8080/api/admin/UpdateRole', {
  2815. method: 'POST',
  2816. headers: {
  2817. 'Authorization': `Bearer ${token}`,
  2818. 'Content-Type': 'application/json'
  2819. },
  2820. body: JSON.stringify(updateRole)
  2821. })
  2822. .then(response => response.json())
  2823. .then(data => {
  2824. if (data.success) {
  2825. alert('角色更新成功!');
  2826. fetchRoles(); // 刷新角色列表
  2827. closeModal('extraInfoModal'); // 关闭信息栏
  2828. } else {
  2829. alert('角色更新失败:' + data.error);
  2830. }
  2831. });
  2832. }
  2833. //删除角色
  2834. function deleteRole(roleName) {
  2835. console.log(`deleteRole called for role: ${roleName}`);
  2836. const confirmed = confirm(`确认删除角色: ${roleName} 吗?`);
  2837. if (!confirmed) {
  2838. return;
  2839. }
  2840. fetch('http://127.0.0.1:8080/api/admin/DeleteRole', {
  2841. method: 'POST',
  2842. headers: {
  2843. 'Authorization': `Bearer ${token}`,
  2844. 'Content-Type': 'application/json'
  2845. },
  2846. body: JSON.stringify({
  2847. name: roleName // 将角色名称传递给后端
  2848. })
  2849. })
  2850. .then(response => response.json())
  2851. .then(data => {
  2852. if (data.success) {
  2853. alert('角色删除成功!');
  2854. fetchRoles(); // 刷新角色列表
  2855. } else {
  2856. alert('角色删除失败:' + data.error);
  2857. }
  2858. })
  2859. .catch(error => {
  2860. console.error('Error deleting role:', error);
  2861. alert('删除角色时发生错误,请稍后再试。');
  2862. });
  2863. }
  2864. document.getElementById('createRoleButton').addEventListener('click', function() {
  2865. const extraInfoContent = document.getElementById('extraInfoContent');
  2866. extraInfoContent.innerHTML = `
  2867. <h3>创建新角色</h3>
  2868. <label for="newRoleName">角色名称:</label>
  2869. <input type="text" id="newRoleName" required><br><br>
  2870. <label for="newPermissions">权限:</label><br>
  2871. <div id="newPermissions">
  2872. <div>
  2873. <input type="checkbox" id="license" name="permissions" value="license" onchange="toggleSubPermissions('license', this)">
  2874. <label for="license">许可证</label>
  2875. <div id="licenseSubPermissions" style="margin-left: 20px;">
  2876. <input type="checkbox" id="generate_license" name="permissions" value="generate_license">
  2877. <label for="generate_license">生成许可证</label><br>
  2878. <input type="checkbox" id="upload_license" name="permissions" value="upload_license">
  2879. <label for="upload_license">上传许可证</label><br>
  2880. <input type="checkbox" id="read_license" name="permissions" value="read_license">
  2881. <label for="read_license">读取许可证</label><br>
  2882. <input type="checkbox" id="update_license" name="permissions" value="update_license">
  2883. <label for="update_license">更新许可证</label><br>
  2884. <input type="checkbox" id="delete_license" name="permissions" value="delete_license">
  2885. <label for="delete_license">删除许可证</label><br>
  2886. </div>
  2887. </div>
  2888. <div>
  2889. <input type="checkbox" id="user" name="permissions" value="user" onchange="toggleSubPermissions('user', this)">
  2890. <label for="user">用户</label>
  2891. <div id="userSubPermissions" style="margin-left: 20px;">
  2892. <input type="checkbox" id="create_user" name="permissions" value="create_user">
  2893. <label for="create_user">创建用户</label><br>
  2894. <input type="checkbox" id="read_user" name="permissions" value="read_user">
  2895. <label for="read_user">读取用户</label><br>
  2896. <input type="checkbox" id="update_user" name="permissions" value="update_user">
  2897. <label for="update_user">更新用户</label><br>
  2898. <input type="checkbox" id="delete_user" name="permissions" value="delete_user">
  2899. <label for="delete_user">删除用户</label><br>
  2900. </div>
  2901. </div>
  2902. <div>
  2903. <input type="checkbox" id="role" name="permissions" value="role" onchange="toggleSubPermissions('role', this)">
  2904. <label for="role">角色</label>
  2905. <div id="roleSubPermissions" style="margin-left: 20px;">
  2906. <input type="checkbox" id="create_role" name="permissions" value="create_role">
  2907. <label for="create_role">创建角色</label><br>
  2908. <input type="checkbox" id="delete_role" name="permissions" value="delete_role">
  2909. <label for="delete_role">删除角色</label><br>
  2910. <input type="checkbox" id="update_role" name="permissions" value="update_role">
  2911. <label for="update_role">更新角色</label><br>
  2912. <input type="checkbox" id="get_role" name="permissions" value="get_role">
  2913. <label for="get_role">获取角色</label><br>
  2914. </div>
  2915. </div>
  2916. </div><br><br>
  2917. <button onclick="createNewRole()">创建</button>
  2918. </div>
  2919. `;
  2920. document.getElementById('extraInfoModal').style.display = 'block';
  2921. });
  2922. function toggleSubPermissions(category, checkbox) {
  2923. const subPermissions = document.querySelectorAll(`#${category}SubPermissions input[type="checkbox"]`);
  2924. subPermissions.forEach(subCheckbox => {
  2925. subCheckbox.checked = checkbox.checked;
  2926. });
  2927. }
  2928. function createNewRole() {
  2929. const newRoleName = document.getElementById('newRoleName').value.trim();
  2930. const selectedPermissions = Array.from(document.querySelectorAll('#newPermissions input[type="checkbox"]:checked'))
  2931. .map(checkbox => checkbox.value)
  2932. .filter(value => !['license', 'user', 'role'].includes(value)); // 过滤掉一级分类
  2933. if (!newRoleName) {
  2934. alert('角色名称不能为空!');
  2935. return;
  2936. }
  2937. const newRole = {
  2938. Name: newRoleName,
  2939. Permissions: selectedPermissions
  2940. };
  2941. fetch('http://127.0.0.1:8080/api/admin/CreateRole', {
  2942. method: 'POST',
  2943. headers: {
  2944. 'Authorization': `Bearer ${token}`,
  2945. 'Content-Type': 'application/json'
  2946. },
  2947. body: JSON.stringify(newRole)
  2948. })
  2949. .then(response => response.json())
  2950. .then(data => {
  2951. if (data.success) {
  2952. alert('角色创建成功!');
  2953. fetchRoles(); // 刷新角色列表
  2954. closeModal('extraInfoModal'); // 关闭信息栏
  2955. } else {
  2956. alert('角色创建失败:' + data.error);
  2957. }
  2958. });
  2959. }
  2960. //显示用户信息
  2961. function showEditUserForm() {
  2962. const extraInfoContent = document.getElementById('extraInfoContent');
  2963. // 清空之前的内容
  2964. extraInfoContent.innerHTML = '';
  2965. // 创建表单
  2966. const form = document.createElement('form');
  2967. form.id = 'editUserForm';
  2968. form.style.width = '400px'; // 增加表单宽度
  2969. form.innerHTML = `
  2970. <div style="display: flex; align-items: center; margin-bottom: 15px;">
  2971. <label for="username" style="flex: 0 0 80px;">用户名:</label>
  2972. <input type="text" id="username" name="username" value="${selectedRowData.Username}" style="flex: 1;" required>
  2973. </div>
  2974. <div style="display: flex; align-items: center; margin-bottom: 15px;">
  2975. <label for="telephone" style="flex: 0 0 80px;">电话:</label>
  2976. <input type="text" id="telephone" name="telephone" value="${selectedRowData.Telephone}" style="flex: 1;" required>
  2977. </div>
  2978. <div style="display: flex; align-items: center; margin-bottom: 15px;">
  2979. <label for="email" style="flex: 0 0 80px;">邮箱:</label>
  2980. <input type="email" id="email" name="email" value="${selectedRowData.Email}" style="flex: 1;" required>
  2981. </div>
  2982. `;
  2983. // 检查用户是否有 'update_role' 权限,如果有,则显示权限选择框
  2984. if (userPermissions.includes('update_role')) {
  2985. const roleSelectDiv = document.createElement('div');
  2986. roleSelectDiv.style = 'display: flex; align-items: center; margin-bottom: 15px;';
  2987. roleSelectDiv.innerHTML = `
  2988. <label for="role" style="flex: 0 0 80px;">权限:</label>
  2989. <select id="role" name="role" style="flex: 1;" required></select>
  2990. `;
  2991. form.appendChild(roleSelectDiv);
  2992. // 获取角色列表并填充到选择框中
  2993. fetch('http://127.0.0.1:8080/api/admin/GetRoleNames', {
  2994. method: 'GET',
  2995. headers: {
  2996. 'Authorization': `Bearer ${token}`,
  2997. 'Content-Type': 'application/json'
  2998. }
  2999. })
  3000. .then(response => response.json())
  3001. .then(data => {
  3002. const roleSelect = document.getElementById('role');
  3003. data.roles.forEach(role => {
  3004. const option = document.createElement('option');
  3005. option.value = role;
  3006. option.textContent = role;
  3007. if (selectedRowData.Role === role) {
  3008. option.selected = true;
  3009. }
  3010. roleSelect.appendChild(option);
  3011. });
  3012. })
  3013. .catch(error => console.error('获取角色列表时出错:', error));
  3014. }
  3015. // 将表单添加到弹出框内容中
  3016. extraInfoContent.appendChild(form);
  3017. // 添加保存按钮
  3018. const saveButton = document.createElement('button');
  3019. saveButton.type = 'button';
  3020. saveButton.onclick = saveUserChanges;
  3021. saveButton.style = 'width: 100%; background-color: #007bff; color: white; border: none; padding: 10px; border-radius: 5px;';
  3022. saveButton.textContent = '保存';
  3023. form.appendChild(saveButton);
  3024. }
  3025. function saveUserChanges() {
  3026. const form = document.getElementById('editUserForm');
  3027. const formData = new FormData(form);
  3028. const updatedUser = {
  3029. Username: formData.get('username'),
  3030. Telephone: formData.get('telephone'),
  3031. Email: formData.get('email'),
  3032. Role: formData.get('role')
  3033. };
  3034. fetch(`http://127.0.0.1:8080/api/admin/updateUser`, {
  3035. method: 'POST',
  3036. headers: {
  3037. 'Authorization': `Bearer ${token}`,
  3038. 'Content-Type': 'application/json'
  3039. },
  3040. body: JSON.stringify({ ...updatedUser, Id: selectedRowData.Id })
  3041. })
  3042. .then(response => response.json())
  3043. .then(data => {
  3044. if (data.success) {
  3045. alert('用户信息更新成功!');
  3046. fetchUsers();
  3047. closeModal('extraInfoModal');
  3048. } else {
  3049. alert('用户信息更新失败:' + data.error);
  3050. }
  3051. });
  3052. }
  3053. //用户个人信息
  3054. function toggleUserInfo() {
  3055. const userModal = document.getElementById('userModal');
  3056. const userButton = document.getElementById('username');
  3057. const rect = userButton.getBoundingClientRect();
  3058. const modalWidth = 300; // 信息栏的宽度
  3059. const windowWidth = window.innerWidth; // 浏览器窗口的宽度
  3060. if (userModal.style.display === 'none' || userModal.style.display === '') {
  3061. fetch(`http://127.0.0.1:8080/api/admin/userInfo`, {
  3062. method: 'GET',
  3063. headers: {
  3064. 'Authorization': `Bearer ${token}`,
  3065. 'Content-Type': 'application/json'
  3066. }
  3067. })
  3068. .then(response => response.json())
  3069. .then(data => {
  3070. const userInfoContent = document.getElementById('userInfoContent');
  3071. let power;
  3072. switch (data.data.Role) {
  3073. case 'admin':
  3074. power = '至高无上的主';
  3075. break;
  3076. case 'supportRole':
  3077. power = '运维';
  3078. break;
  3079. case 'guest':
  3080. power = '访客';
  3081. break;
  3082. default:
  3083. power = data.data.Role;
  3084. }
  3085. userInfoContent.innerHTML = `
  3086. <h2> 个人信息</h2>
  3087. <div class="apple-modal-content">
  3088. <p class="apple-modal-text"><strong>用户名:</strong> ${data.data.Username}</p>
  3089. <p class="apple-modal-text"><strong>账号:</strong> ${data.data.Account}</p>
  3090. <p class="apple-modal-text"><strong>邮箱:</strong> ${data.data.Email}</p>
  3091. <p class="apple-modal-text"><strong>电话:</strong> ${data.data.Telephone}</p>
  3092. <p class="apple-modal-text"><strong>权限:</strong> ${power}</p>
  3093. </div>
  3094. `;
  3095. // 设置模态框位置
  3096. userModal.style.top = `${rect.bottom + window.scrollY + 10}px`;
  3097. const leftPosition = rect.right + window.scrollX + 20; // 右侧位置
  3098. const rightEdge = leftPosition + modalWidth;
  3099. if (rightEdge > windowWidth) {
  3100. const leftEdge = rect.left + window.scrollX - modalWidth - 20;
  3101. userModal.style.left = `${Math.max(20, leftEdge)}px`;
  3102. } else {
  3103. userModal.style.left = `${leftPosition}px`;
  3104. }
  3105. userModal.style.display = 'block';
  3106. userModal.style.opacity = '0'; // 先设置透明度为0
  3107. setTimeout(() => {
  3108. userModal.style.opacity = '1'; // 然后慢慢显示
  3109. }, 0); // 延迟一帧显示
  3110. userModal.style.transition = 'opacity 0.3s ease, top 0.3s ease, left 0.3s ease';
  3111. // 添加全局点击监听器
  3112. document.addEventListener('click', handleClickOutsideModal);
  3113. });
  3114. } else {
  3115. closeUserInfo();
  3116. }
  3117. }
  3118. function closeUserInfo() {
  3119. const userModal = document.getElementById('userModal');
  3120. userModal.style.opacity = '0'; // 先设置透明度为0
  3121. setTimeout(() => {
  3122. userModal.style.display = 'none'; // 然后隐藏
  3123. }, 300); // 延迟0.3秒,等待过渡结束
  3124. // 移除全局点击监听器
  3125. document.removeEventListener('click', handleClickOutsideModal);
  3126. }
  3127. function closeUserInfo() {
  3128. const userModal = document.getElementById('userModal');
  3129. userModal.style.opacity = '0'; // 先设置透明度为0
  3130. setTimeout(() => {
  3131. userModal.style.display = 'none'; // 然后隐藏
  3132. }, 300); // 延迟0.3秒,等待过渡结束
  3133. // 移除全局点击监听器
  3134. document.removeEventListener('click', handleClickOutsideModal);
  3135. }
  3136. function handleClickOutsideModal(event) {
  3137. const userModal = document.getElementById('userModal');
  3138. if (!userModal.contains(event.target) && event.target.id !== 'username') {
  3139. closeUserInfo();
  3140. }
  3141. }
  3142. //用户退出
  3143. function logout() {
  3144. localStorage.removeItem('Authorization');
  3145. window.location.href = '/';
  3146. }
  3147. function showUserManagement() {
  3148. document.getElementById('table-container').style.display = 'none';
  3149. document.getElementById('role-management').style.display = 'none'; // 隐藏角色管理页面
  3150. document.getElementById('user-management').style.display = 'block';
  3151. // 检查用户是否有 create_user 权限
  3152. const hasCreateUserPermission = userPermissions.includes('create_user');
  3153. // 获取添加用户按钮元素
  3154. const addUserButton = document.getElementById('addUserButton');
  3155. // 根据权限显示或隐藏添加用户按钮
  3156. if (hasCreateUserPermission) {
  3157. addUserButton.style.display = 'block';
  3158. } else {
  3159. addUserButton.style.display = 'none';
  3160. }
  3161. // 加载用户列表
  3162. fetchUsers();
  3163. }
  3164. function showTable() {
  3165. document.getElementById('user-management').style.display = 'none';
  3166. document.getElementById('role-management').style.display = 'none'; // 隐藏角色管理页面
  3167. document.getElementById('table-container').style.display = 'block';
  3168. }
  3169. function toggleSidebar() {
  3170. const sidebar = document.getElementById('sidebar');
  3171. const content = document.getElementById('content');
  3172. sidebar.classList.toggle('hidden');
  3173. content.classList.toggle('expanded');
  3174. const toggleButton = document.querySelector('.toggle-sidebar');
  3175. if (sidebar.classList.contains('hidden')) {
  3176. toggleButton.innerHTML = '>'; // 当侧边栏隐藏时,显示右箭头
  3177. } else {
  3178. toggleButton.innerHTML = '<'; // 当侧边栏显示时,显示左箭头
  3179. }
  3180. }
  3181. function fetchUsername() {
  3182. fetch(`http://127.0.0.1:8080/api/admin/userInfo`, {
  3183. method: 'GET',
  3184. headers: {
  3185. 'Authorization': `Bearer ${token}`,
  3186. 'Content-Type': 'application/json'
  3187. }
  3188. })
  3189. .then(response => response.json())
  3190. .then(data => {
  3191. document.getElementById('username').textContent = data.data.Username;
  3192. currentUserRole = data.data.Role; // 存储当前用户的角色
  3193. currentUserName = data.data.Username
  3194. // 使用获取到的角色,调用获取权限的接口
  3195. fetchPermissionsByRole(currentUserRole)
  3196. .then(() => {
  3197. //fetchApplications(LisOffset, pageSize); // 确保在权限获取之后才调用 fetchApplications
  3198. const startOffset = currentOffset; // 当前的起始位置
  3199. const endOffset = startOffset + itemsPerPage - 1; // 计算结束位置
  3200. fetchApplications(startOffset, endOffset); // 传入计算好的起始和结束位置
  3201. // 检查用户是否有 upload_license 权限
  3202. const hasUploadLicensePermission = userPermissions.includes('upload_license');
  3203. // 获取上传按钮元素
  3204. const uploadButton = document.querySelector('.upload-button');
  3205. // 根据权限显示或隐藏上传按钮
  3206. // if (hasUploadLicensePermission) {
  3207. // uploadButton.style.display = 'inline-block'; // 显示按钮
  3208. // } else {
  3209. // uploadButton.style.display = 'none'; // 隐藏按钮
  3210. // }
  3211. // 是否生成主动抓取lic按钮
  3212. checkCaptureLicensePermission();
  3213. // 检查是否有 capture_license_once_to_db 权限
  3214. });
  3215. });
  3216. }
  3217. function fetchPermissionsByRole(role) {
  3218. return fetch(`http://127.0.0.1:8080/api/admin/GetSelfRoles`, {
  3219. method: 'POST',
  3220. headers: {
  3221. 'Authorization': `Bearer ${token}`,
  3222. 'Content-Type': 'application/json'
  3223. },
  3224. body: JSON.stringify({ name: role })
  3225. })
  3226. .then(response => response.json())
  3227. .then(data => {
  3228. userPermissions = data.data.Permissions; // 获取用户的权限数组
  3229. console.log('userPermissions:', userPermissions);
  3230. // 定义权限类别
  3231. const licensePermissions = ['upload_license', 'read_license'];
  3232. const userPermissionsCheck = [ 'create_user', 'read_user', 'update_user', 'delete_user'];
  3233. const rolePermissions = ['create_role', 'delete_role', 'update_role', 'get_role'];
  3234. const hasLicenseAccess = licensePermissions.some(permission => userPermissions.includes(permission));
  3235. const hasUserManagementAccess = userPermissionsCheck.some(permission => userPermissions.includes(permission));
  3236. const hasRoleManagementAccess = rolePermissions.some(permission => userPermissions.includes(permission));
  3237. // 根据权限渲染菜单并显示初始页面
  3238. renderMenuAndInitialPage(hasLicenseAccess, hasUserManagementAccess, hasRoleManagementAccess);
  3239. });
  3240. }
  3241. function renderMenuAndInitialPage(hasLicenseAccess, hasUserManagementAccess, hasRoleManagementAccess) {
  3242. const sidebar = document.querySelector('.sidebar');
  3243. // 清空现有菜单项
  3244. sidebar.innerHTML = '';
  3245. let initialPageShown = false;
  3246. // 动态添加菜单项并确定初始显示的页面
  3247. if (hasLicenseAccess) {
  3248. const licenseButton = document.createElement('button');
  3249. licenseButton.textContent = 'License 管理';
  3250. licenseButton.onclick = showTable;
  3251. sidebar.appendChild(licenseButton);
  3252. if (!initialPageShown) {
  3253. showTable(); // 如果有License权限,先显示License页面
  3254. initialPageShown = true;
  3255. }
  3256. }
  3257. if (hasUserManagementAccess) {
  3258. const userManagementButton = document.createElement('button');
  3259. userManagementButton.textContent = '用户管理';
  3260. userManagementButton.onclick = showUserManagement;
  3261. sidebar.appendChild(userManagementButton);
  3262. if (!initialPageShown) {
  3263. showUserManagement(); // 如果没有License权限,但有用户管理权限,显示用户管理页面
  3264. initialPageShown = true;
  3265. }
  3266. }
  3267. if (hasRoleManagementAccess) {
  3268. const roleManagementButton = document.createElement('button');
  3269. roleManagementButton.textContent = '角色管理';
  3270. roleManagementButton.onclick = showRoleManagement;
  3271. sidebar.appendChild(roleManagementButton);
  3272. if (!initialPageShown) {
  3273. showRoleManagement(); // 如果没有License和用户管理权限,但有角色管理权限,显示角色管理页面
  3274. initialPageShown = true;
  3275. }
  3276. }
  3277. if (!initialPageShown && sidebar.firstChild) {
  3278. sidebar.firstChild.click(); // 如果没有优先的权限页面,则显示菜单中的第一个页面
  3279. }
  3280. }
  3281. // 添加到每个模态框的 JavaScript 部分
  3282. document.addEventListener('DOMContentLoaded', function() {
  3283. // 获取所有模态框
  3284. const modals = document.querySelectorAll('.modal');
  3285. // 为每个模态框添加点击事件监听器
  3286. modals.forEach(modal => {
  3287. modal.addEventListener('click', function(event) {
  3288. // 如果点击的是模态框背景而不是模态框内容,关闭模态框
  3289. if (event.target === modal) {
  3290. modal.style.display = 'none';
  3291. }
  3292. });
  3293. });
  3294. });
  3295. // 页面初始化时调用 fetchUsername 函数
  3296. fetchUsername();
  3297. //fetchApplications(currentPage, pageSize);
  3298. </script>
  3299. </body>
  3300. </html>