license_info copy 2.html 117 KB

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