diff --git a/auto_pt/urls.py b/auto_pt/urls.py index 1061b21..a6d7c98 100644 --- a/auto_pt/urls.py +++ b/auto_pt/urls.py @@ -27,6 +27,7 @@ urlpatterns = [ path(r'sign_in_api', views.sign_in_api, name='sign_in_api'), path(r'update_site_api', views.update_site_api, name='update_site_api'), path(r'edit_site_api', views.edit_site_api, name='edit_site_api'), + path(r'site_sort_api', views.site_sort_api, name='site_sort_api'), path(r'get_log_list', views.get_log_list, name='get_log_list'), path(r'show_log_list', views.show_log_list, name='show_log_list'), path(r'get_log_content', views.get_log_content, name='get_log_content'), diff --git a/auto_pt/views.py b/auto_pt/views.py index 6cdfcc5..6b10700 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -624,6 +624,7 @@ def site_status_api(request): 'time_join': my_site.time_join, 'hr': my_site.my_hr, 'mail': my_site.mail, + 'sort_id': my_site.sort_id, 'sp': site_info.my_sp, 'bonus': site_info.my_bonus, # 'uploaded': FileSizeConvert.parse_2_file_size(site_info.uploaded), @@ -637,7 +638,7 @@ def site_status_api(request): status_list.append(site_info) # 按上传量排序 # status_list.sort(key=lambda x: x['mail'], reverse=False) - status_list.sort(key=lambda x: (x['mail'], x['uploaded']), reverse=True) + # status_list.sort(key=lambda x: (x['mail'], x['sort_id']), reverse=True) # sorted(status_list, key=lambda x: x['uploaded']) # 随机乱序 # random.shuffle(status_list) @@ -835,3 +836,29 @@ def get_log_content(request): def show_log_list(request): return render(request, 'auto_pt/showlog.html') + + +def site_sort_api(request): + try: + my_site_id = request.GET.get('id') + sort = request.GET.get('sort') + logger.info(f'ID值:{type(my_site_id)}') + my_site = MySite.objects.filter(id=my_site_id).first() + my_site.sort_id += int(sort) + + if int(my_site.sort_id) <= 0: + my_site.sort_id = 0 + my_site.save() + return JsonResponse(data=CommonResponse.success( + msg='排序已经最靠前啦,不要再点了!' + ).to_dict(), safe=False) + my_site.save() + return JsonResponse(data=CommonResponse.success( + msg='排序成功!' + ).to_dict(), safe=False) + except Exception as e: + logger.error(f'数据更新失败:{e}') + logger.error(traceback.format_exc(limit=3)) + return JsonResponse(data=CommonResponse.error( + msg=f'数据更新失败:{e}' + ).to_dict(), safe=False) diff --git a/static/js/utils.js b/static/js/utils.js index 2466e1d..70fff1b 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -28,6 +28,5 @@ function numberFormat(value) { param.value = ((value / Math.pow(k, i))).toFixed(2); param.unit = sizes[i]; } - console.log(param) return `${param.value}${param.unit}`; } diff --git a/templates/auto_pt/status.html b/templates/auto_pt/status.html index 62e1dca..f9c8bfd 100644 --- a/templates/auto_pt/status.html +++ b/templates/auto_pt/status.html @@ -68,6 +68,9 @@
+
+ +
@@ -115,6 +118,17 @@

+
+ + 排序 + + + + 排序按钮单次步进值: + + +
+
保种分享:
+
@@ -176,12 +191,10 @@
- - -
+
-{#
#} -{# #} -{# {}#} -{#
#} + +
@@ -221,7 +231,27 @@ {# #} 历史 +
+
+
+ + 排序 + + + + + + + + + +
+
保种分享: @@ -256,7 +286,8 @@ v-text="' ' + numberFormat(site.sp) + ' / ' + numberFormat(site.bonus)" style="color: darkorange" title="魔力/积分">
-

@@ -331,13 +362,16 @@ return { chart: null, ptData: {}, + siteData: [], option: {}, - showList: false, + showList: true, showSiteChart: false, begInvite: false, showLogo: true, showLegend: true, shuffle: false, + searchKey: '', + sortStep: 1, } }, beforeMount() { @@ -353,14 +387,57 @@ // option发生变化时自动重新渲染 this.chart.setOption(newValue) }, + searchKey(newValue, oldValue) { + console.log(newValue) + }, // immediate: true, deep: true, } }, methods: { + siteSearch() { + + }, + changeSortStep() { + console.log(this.sortStep) + if (this.sortStep < 5) { + this.sortStep += 1 + } else { + this.sortStep = 1 + } + }, + sortCustom(id, sort) { + console.log(sort) + axios.get( + "{% url 'site_sort_api' %}" + `?id=${id}&sort=${sort}` + ).then(res => { + console.log('修改排序成功', res.data) + {#let data = res.data#} + {#console.log(typeof res.data.data)#} + if (res.data.code === 0) { + this.$message({ + type: 'success', + message: res.data.msg + }); + this.getData() + } else { + this.loading = false + this.$message({ + type: 'warning', + message: res.data.msg + }); + } + }).catch(res => { + console.log('修改排序失败', res) + this.$message({ + type: 'warning', + message: '修改排序失败!' + res + }); + }) + }, signIn(id) { axios.get( - "{% url 'sign_in_api' %}" + '?id=' + id + "{% url 'sign_in_api' %}" + `?id=${id}` ).then(res => { console.log('获取数据列表成功', res.data) {#let data = res.data#} @@ -478,18 +555,15 @@ } this.setPie() - } - , + }, showLogoMode() { this.showLogo = !this.showLogo this.setPie() - } - , + }, showLegendMode() { this.showLegend = !this.showLegend this.setPie() - } - , + }, setChartOption(option) { {#this.option = option#} if (this.chart) { @@ -502,8 +576,7 @@ //this.$nextTick(() => {//自适应宽度 // this.chart.resize(); //}) - } - , + }, shuffleList() { this.shuffle = true this.ptData.status_list.sort(() => { @@ -511,8 +584,7 @@ }) this.showList ? this.setCard() : this.setPie() - } - , + }, sortList() { //if (this.shuffle == false) { // return @@ -520,13 +592,15 @@ this.shuffle = false this.ptData.status_list.sort((a, b) => { if (b.mail == a.mail) { - return b.uploaded - a.uploaded + if (b.sort_id == a.sort_id) { + return b.id - a.id + } + return a.sort_id - b.sort_id } return b.mail - a.mail }) this.showList ? this.setCard() : this.setPie() - } - , + }, setCard() { if (this.chart) { this.chart.clear() @@ -592,16 +666,16 @@ return renderSize(value) } }, - color: [ - '#f66c73', - '#f68645', - '#7af6ad', - '#f4d55f', - '#488ff6', - '#0fba8d', - '#8a47dc', - '#d677f6', - ], + {#color: [#} + {# '#f66c73',#} + {# '#f68645',#} + {# '#7af6ad',#} + {# '#f4d55f',#} + {# '#488ff6',#} + {# '#0fba8d',#} + {# '#8a47dc',#} + {# '#d677f6',#} + {#],#} legend: { show: this.showLegend, {#type: 'scroll',#} @@ -962,7 +1036,8 @@ {#this.ptData = res.data.data#} this.ptData = res.data.data {#this.setPie()#} - this.setCard() + {#this.setCard()#} + this.sortList() } else { this.loading = false this.$message({