main.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. function requestApi(functionName, args, callback, showResults, refreshPageWhenSuccess, disableBtnId) {
  2. $(disableBtnId).attr("disabled", true);
  3. setTimeout(function() {
  4. $(disableBtnId).attr("disabled", false);
  5. }, 200000)
  6. $("#isLoading").show(100)
  7. $.ajax({
  8. type: 'post',
  9. url: '/api/' + functionName + '.php',
  10. data: args,
  11. dataType: 'json',
  12. success: function(rdata) {
  13. if (showResults) {
  14. mdui.snackbar({
  15. message: rdata.msg,
  16. position: 'right-top'
  17. })
  18. }
  19. if (refreshPageWhenSuccess & rdata.code == 1) {
  20. $.pjax.reload({
  21. container: "#pjax-container"
  22. })
  23. }
  24. $("#isLoading").hide(100)
  25. $(disableBtnId).attr("disabled", false)
  26. if (callback) {
  27. callback(rdata)
  28. }
  29. },
  30. error: function(data) {
  31. $("#isLoading").hide(100)
  32. $(disableBtnId).attr("disabled", false)
  33. mdui.snackbar({
  34. message: "请求接口[" + functionName + "]时,出现了一个致命错误!",
  35. position: 'right-top'
  36. })
  37. }
  38. })
  39. }
  40. function randomNumBoth(Min, Max) {
  41. var Range = Max - Min;
  42. var Rand = Math.random();
  43. var num = Min + Math.round(Rand * Range);
  44. return num;
  45. }
  46. function randomImage(that) {
  47. var that = $(window.event.target)
  48. if (window.imglist == undefined) {
  49. $.get("https://img.llilii.cn/imglist/kagamine.json", function(rdata) {
  50. window.imglist = rdata
  51. window.base_url_origin = imglist['base_url']['origin']['public'][randomNumBoth(0, parseInt(imglist['base_url']['compression']['public'].length) - 1)]
  52. window.base_url_compression = imglist['base_url']['compression']['public'][randomNumBoth(0, parseInt(imglist['base_url']['compression']['public'].length) - 1)]
  53. image_id = randomNumBoth(0, parseInt(imglist['info']['count']) - 1)
  54. image_name = imglist['filename'][image_id]
  55. that.attr('src', base_url_compression + "/" + image_name)
  56. that.attr('origin-src', window.base_url_origin + "/" + image_name)
  57. })
  58. } else {
  59. image_id = randomNumBoth(0, parseInt(imglist['info']['count']) - 1)
  60. image_name = imglist['filename'][image_id]
  61. that.attr('src', base_url_compression + "/" + image_name)
  62. that.attr('origin-src', window.base_url_origin + "/" + image_name)
  63. }
  64. that.attr('onerror', null)
  65. }
  66. function imageVerification(callback) {
  67. mdui.dialog({
  68. title: '请输入图片中的验证码',
  69. content: '<center><div class="mdui-row"> <div class="mdui-col-xs-9"> <div class="mdui-textfield"> <input class="mdui-textfield-input" id="answer" type="text" placeholder="请输入您的答案" /></div> </div> <div class="mdui-col-xs-3"> <img style="position: relative;top:15px" id="vcode" src="/api/vcode.php" /> </div> </div></center>',
  70. modal: true,
  71. buttons: [{
  72. text: '取消'
  73. },
  74. {
  75. text: '确认',
  76. onClick: function(inst) {
  77. callback($('#answer').val());
  78. }
  79. }
  80. ]
  81. });
  82. }
  83. function search() {
  84. mdui.prompt('支持从名字、表白内容中搜索', '搜索',
  85. function(value) {
  86. setTimeout(function() {
  87. $.pjax({
  88. url: '/?search=' + value,
  89. container: '#pjax-container'
  90. });
  91. }, 10)
  92. }
  93. )
  94. }
  95. function jumpPage() {
  96. mdui.prompt('你要跳转到第几页?', '快速翻页',
  97. function(value) {
  98. setTimeout(function() {
  99. $.pjax({
  100. url: '?p=' + value,
  101. container: '#pjax-container'
  102. });
  103. }, 10)
  104. }
  105. )
  106. }
  107. function logout() {
  108. setCookie('loveway_token', "kagamine yes!", -1);
  109. mdui.snackbar({
  110. message: "登出成功!",
  111. position: 'right-top'
  112. });
  113. $.pjax.reload({
  114. container: "#pjax-container"
  115. })
  116. }