license_info copy 2.html 139 KB

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