old_license_info.html 119 KB

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