license_info copy 3.html 125 KB

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