license_info.html 135 KB

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