license_info copy 4.html 134 KB

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