From c36ab08f359fbd55598b09e051347bcfec84c37c Mon Sep 17 00:00:00 2001 From: nineven Date: Sat, 14 May 2022 11:38:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=98=E5=82=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=92=8C=E5=B1=95=E7=A4=BA=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/user/FirSuperSignBase.vue | 19 +- .../src/components/user/FirUserStorage.vue | 202 ++++++++++++------ fir_ser/api/utils/serializer.py | 10 +- fir_ser/api/views/storage.py | 29 ++- fir_ser/xsign/utils/serializer.py | 7 - fir_ser/xsign/views/supersign.py | 4 +- 6 files changed, 185 insertions(+), 86 deletions(-) diff --git a/fir_client/src/components/user/FirSuperSignBase.vue b/fir_client/src/components/user/FirSuperSignBase.vue index 370d0da..9815d9b 100644 --- a/fir_client/src/components/user/FirSuperSignBase.vue +++ b/fir_client/src/components/user/FirSuperSignBase.vue @@ -1373,7 +1373,13 @@ label="设备数量" prop="number" width="100"> - + { if (data.code === 1000) { @@ -2071,6 +2085,9 @@ export default { DeviceTransferBillInfo(data => { if (data.code === 1000) { this.transferInfo = data.data + if (this.transferInfo.number) { + this.target_number = this.transferInfo.number + } this.cantransfer = false } else { this.cantransfer = true diff --git a/fir_client/src/components/user/FirUserStorage.vue b/fir_client/src/components/user/FirUserStorage.vue index 93172cf..0365c31 100644 --- a/fir_client/src/components/user/FirUserStorage.vue +++ b/fir_client/src/components/user/FirUserStorage.vue @@ -193,22 +193,50 @@ - - 存储选择: - - - - - - + ' + + + 存储选择: + + + + + + + + + +
+ 存储最大容量空间: {{ diskSize(storageinfo.max_storage_capacity) }} + 已经使用容量: {{ diskSize(storageinfo.used_number) }} + 当前可用容量: + {{ diskSize(storageinfo.max_storage_capacity - storageinfo.used_number) }} + +
+ + 还剩:{{ diskSize(storageinfo.max_storage_capacity - storageinfo.used_number) }} 可用 + +
+ +
+
+ +
-->
- @@ -245,64 +273,66 @@ 可用容量{{ diskSize(storageinfo.max_storage_capacity - storageinfo.used_number) }} - - - - - - - -
- - - +
+ + + + + - - - - - - - - - +
-
- - + + - - + + + + + + + + - - - - +
+ + + + + + + + + + + + + + + + - - +
+ +
- - - -
@@ -719,7 +749,7 @@ export default { dialogstorageVisible: false, editstorageinfo: {}, selectlabel: "", - storageinfo: {}, + storageinfo: {'used_number': 0, 'max_storage_capacity': 1}, storage_list: [], endpoint_list: [], disabled: true, @@ -735,12 +765,36 @@ export default { }, methods: { format_time, diskSize, + storage_usedColor(percentage) { + if (percentage < 20) { + return '#6f7ad3'; + } else if (percentage < 40) { + return '#1989fa'; + } else if (percentage < 60) { + return '#5cb87a'; + + } else if (percentage < 80) { + return '#e6a23c'; + } else if (percentage < 90) { + return '#E63918'; + } else { + return '#F50346'; + } + }, updateConfig() { + const loading = this.$loading({ + lock: true, + text: '执行中,请耐心等待...', + spinner: 'el-icon-loading', + background: 'rgba(0, 0, 0, 0.7)' + }); configStorageData(res => { + loading.close() if (res.code === 1000) { + this.$message.success("操作成功") this.storage_config = res.data } else { - this.$message.error("获取数据失败了," + res.msg) + this.$message.error("操作失败了," + res.msg) } }, {"methods": "PUT", "data": this.storage_config}) }, @@ -767,8 +821,8 @@ export default { this.use_storage_id = row.storage_id; } else { this.use_storage_id = data.storage; + this.formatStorageId() } - this.formatStorageId() if (row && row.target_user) { this.target_uid = row.target_user.uid this.checkuid(this.target_uid) @@ -781,7 +835,7 @@ export default { }, {"methods": 'GET', "data": {'act': 'storage_group', 'is_default': false}}); }, editShareStorage(row) { - if (row.status !== 1) return + // if (row.status !== 1) return if (!row.cancel) return this.shareStorage(row) }, @@ -938,6 +992,7 @@ export default { return } } + this.editstorageinfo.storage_capacity = this.editstorageinfo.max_storage_capacity getStorageinfo(data => { if (data.code === 1000) { this.$message.success('操作成功'); @@ -1039,10 +1094,10 @@ export default { this.getstorageinfobyid(a); }, getstorageinfobyid(id) { - if (id === -1) { - this.storageinfo = {} - return - } + // if (id === -1) { + // this.storageinfo = {} + // return + // } this.target_number = parseInt(this.getSizeFromId() / 1024 / 1024) getStorageinfo(data => { if (data.code === 1000) { @@ -1147,6 +1202,13 @@ export default { computed: { watchObj() { return [this.editstorageinfo.endpoint, this.editstorageinfo.bucket_name, this.editstorageinfo.download_auth_type] + }, + percentage() { + let p = parseInt(this.storageinfo.used_number * 100 / this.storageinfo.max_storage_capacity); + if (p < 0 || p >= 100) { + p = 100 + } + return p } } } diff --git a/fir_ser/api/utils/serializer.py b/fir_ser/api/utils/serializer.py index f2597e1..678d742 100644 --- a/fir_ser/api/utils/serializer.py +++ b/fir_ser/api/utils/serializer.py @@ -370,21 +370,22 @@ class StorageSerializer(serializers.ModelSerializer): storage_type = attrs.get('storage_type', '') if storage_type == 2 and endpoint not in Config.STORAGE_ALLOW_ENDPOINT: raise ValidationError(f'endpoint [{endpoint}] not in {Config.STORAGE_ALLOW_ENDPOINT}') - max_storage_capacity = attrs.get('max_storage_capacity', -1) + max_storage_capacity = attrs.get('storage_capacity', -1) if max_storage_capacity != -1: attrs['max_storage_capacity'] = max_storage_capacity * 1024 * 1024 elif max_storage_capacity == 0: attrs['max_storage_capacity'] = Config.STORAGE_OSS_CAPACITY else: - del attrs['max_storage_capacity'] + del attrs['storage_capacity'] return attrs storage_type_display = serializers.CharField(source="get_storage_type_display", read_only=True) - + storage_capacity = serializers.IntegerField(write_only=True) download_auth_type_choices = serializers.SerializerMethodField() used = serializers.SerializerMethodField() used_number = serializers.SerializerMethodField() shared = serializers.SerializerMethodField() + max_storage_capacity = serializers.SerializerMethodField() def get_used(self, obj): return obj.app_storage.count() @@ -395,6 +396,9 @@ class StorageSerializer(serializers.ModelSerializer): def get_used_number(self, obj): return get_user_storage_used(obj.app_storage.all()) + def get_max_storage_capacity(self, obj): + return obj.max_storage_capacity if obj.max_storage_capacity != 0 else Config.STORAGE_OSS_CAPACITY + # secret_key = serializers.SerializerMethodField() # 加上此选项,会导致update获取不到值 # def get_secret_key(self, obj): diff --git a/fir_ser/api/views/storage.py b/fir_ser/api/views/storage.py index 3243dc8..1097970 100644 --- a/fir_ser/api/views/storage.py +++ b/fir_ser/api/views/storage.py @@ -87,6 +87,26 @@ class StorageView(APIView): if act == 'storage_group': res.storage_group_list = get_storage_group(request, res, self.storage_type, is_default == 'true') return Response(res.dict) + if pk: + if pk == '-1': + storage_capacity = request.user.storage_capacity + default_storage = { + 'id': -1, + 'max_storage_capacity': storage_capacity if storage_capacity != 0 else Config.STORAGE_FREE_CAPACITY, + 'used_number': get_user_storage_used(request.user) + } + res.data = [default_storage] + return Response(res.dict) + else: + share_obj = StorageShareInfo.objects.filter(to_user_id=request.user, storage_id_id=pk, status=1).first() + if share_obj: + default_storage = { + 'id': -1, + 'max_storage_capacity': share_obj.number, + 'used_number': get_user_storage_used(request.user) + } + res.data = [default_storage] + return Response(res.dict) # [1,2] 表示七牛存储和阿里云存储 storage_queruset = AppStorage.objects.filter(user_id=request.user, storage_type__in=self.storage_type) @@ -308,7 +328,7 @@ class ShareStorageView(APIView): status=1, storage_id=storage_obj).first() if share_obj: # number += share_obj.number - share_obj.number = number if number < storage_capacity else storage_capacity + share_obj.number = number share_obj.remote_addr = get_real_ip_address(request) share_obj.description = f'{user_obj.first_name} 共享给 {to_user_obj.first_name} {share_obj.number} Mb存储空间 ' share_obj.save(update_fields=['number', 'remote_addr', 'description']) @@ -409,10 +429,15 @@ class StorageConfigView(APIView): history_release_limit = request.data.get('user_history_limit') if history_release_limit: try: - history_release_limit = int(history_release_limit) + history_release_limit = int(history_release_limit) if int( + history_release_limit) > 0 else request.user.history_release_limit except Exception as e: logger.warning(f"update user history_release_limit failed Exception:{e}") history_release_limit = request.user.history_release_limit UserInfo.objects.filter(pk=request.user.pk).update(history_release_limit=abs(history_release_limit)) + app_obj_lists = Apps.objects.filter(user_id=request.user).all() + for app_obj in app_obj_lists: + clean_history_apps(app_obj, request.user, abs(history_release_limit)) + return self.get(request) diff --git a/fir_ser/xsign/utils/serializer.py b/fir_ser/xsign/utils/serializer.py index cf11b17..3ff3351 100644 --- a/fir_ser/xsign/utils/serializer.py +++ b/fir_ser/xsign/utils/serializer.py @@ -240,7 +240,6 @@ class BillTransferSerializer(serializers.ModelSerializer): target_user = serializers.SerializerMethodField() cancel = serializers.SerializerMethodField() - number = serializers.SerializerMethodField() status_display = serializers.CharField(source='get_status_display') def get_target_user(self, obj): @@ -252,12 +251,6 @@ class BillTransferSerializer(serializers.ModelSerializer): def get_cancel(self, obj): return self.context.get('user_obj').pk == obj.user_id.pk - def get_number(self, obj): - if self.get_cancel(obj): - return -obj.number - else: - return obj.number - class AppleDeveloperToAppUseSerializer(serializers.ModelSerializer): class Meta: diff --git a/fir_ser/xsign/views/supersign.py b/fir_ser/xsign/views/supersign.py index b1c91c5..40eb72e 100644 --- a/fir_ser/xsign/views/supersign.py +++ b/fir_ser/xsign/views/supersign.py @@ -700,9 +700,7 @@ class DeviceTransferBillView(APIView): bill_obj = IosDeveloperBill.objects.filter(user_id=user_obj, to_user_id=to_user_obj, status=2).first() if bill_obj: - bill_obj.number = number + bill_obj.number - if bill_obj.number >= all_balance: - bill_obj.number = all_balance + bill_obj.number = number if number < all_balance else all_balance bill_obj.remote_addr = get_real_ip_address(request) bill_obj.description = f'{user_obj.first_name} 共享给 {to_user_obj.first_name} {bill_obj.number} 设备数' bill_obj.save(update_fields=['number', 'remote_addr', 'description'])