license_info copy 主行分页展示版本.html 139 KB

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