index.js.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // Created by xcbosa on 2023-01-31
  3. //
  4. #include "../../processor/processor.h"
  5. #include "../../utils/utils.h"
  6. #include "../../webuiconf.h"
  7. using namespace std;
  8. using namespace xc::processor;
  9. using namespace xc::utils;
  10. using namespace xc::processor::templates;
  11. namespace xc::controller {
  12. static string ControllerPath = "/index.js";
  13. static ResponseData *controllerResponse(RequestData request) {
  14. return new TextResponseData(200,
  15. string("let app = new Framework7({\n") +
  16. string(" // App root element\n") +
  17. string(" el: \'#app\',\n") +
  18. string(" // App Name\n") +
  19. string(" name: \'FRPCWebUI\',\n") +
  20. string(" // App id\n") +
  21. string(" id: \'org.forgetive.frpcwebui\',\n") +
  22. string(" // Enable swipe panel\n") +
  23. string(" panel: {\n") +
  24. string(" swipe: true,\n") +
  25. string(" },\n") +
  26. string(" // Add default routes,\n") +
  27. string(" autoDarkMode: true,\n") +
  28. string(" routes: [\n") +
  29. string(" {\n") +
  30. string(" path: \'/about/\',\n") +
  31. string(" url: \'about.html\',\n") +
  32. string(" },\n") +
  33. string(" ]\n") +
  34. string("});\n") +
  35. string("\n") +
  36. string("function createGuage(elAppendix, valueText, description, value, size) {\n") +
  37. string(" app.gauge.create({\n") +
  38. string(" el: \'.gauge_template_\' + elAppendix,\n") +
  39. string(" type: \'circle\',\n") +
  40. string(" value: value,\n") +
  41. string(" size: size,\n") +
  42. string(" borderColor: \'#2196f3\',\n") +
  43. string(" borderWidth: 10,\n") +
  44. string(" valueText: valueText,\n") +
  45. string(" valueFontSize: 41,\n") +
  46. string(" valueTextColor: \'#2196f3\',\n") +
  47. string(" labelText: description,\n") +
  48. string(" })\n") +
  49. string("}\n") +
  50. string("\n") +
  51. string("function doLogin(salt) {\n") +
  52. string(" let data = app.form.convertToData(\"#loginForm\")\n") +
  53. string(" if (data.username.length == 0) {\n") +
  54. string(" app.dialog.alert(\"请输入用户名\")\n") +
  55. string(" return\n") +
  56. string(" }\n") +
  57. string(" if (data.password.length == 0) {\n") +
  58. string(" app.dialog.alert(\"请输入密码\")\n") +
  59. string(" return\n") +
  60. string(" }\n") +
  61. string(" data.password = sha256_digest(data.password + salt)\n") +
  62. string(" window.location = \"/login?v=\" + JSON.stringify(data)\n") +
  63. string(" return\n") +
  64. string("}\n")
  65. , mimeTypeOfFile(ControllerPath));
  66. }
  67. ContentGeneratorDefineS(request.getURLPath() == ControllerPath, controllerResponse(request))
  68. }