license_info copy.html 130 KB

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