license_info_bak.html 111 KB

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