diff --git a/apps/customers/admin.py b/apps/customers/admin.py index 4730f17..ba08ace 100644 --- a/apps/customers/admin.py +++ b/apps/customers/admin.py @@ -20,6 +20,6 @@ class CustomerLocationAdmin(admin.ModelAdmin): 'fields': ('address_zh', 'address_en', 'description_zh', 'description_en') }), ('显示', { - 'fields': ('marker_color', 'sort_order', 'is_active') + 'fields': ('marker_color', 'marker_icon', 'sort_order', 'is_active') }), ) diff --git a/apps/customers/migrations/0002_customerlocation_marker_icon.py b/apps/customers/migrations/0002_customerlocation_marker_icon.py new file mode 100644 index 0000000..e080f68 --- /dev/null +++ b/apps/customers/migrations/0002_customerlocation_marker_icon.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.14 on 2026-08-03 08:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('customers', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='customerlocation', + name='marker_icon', + field=models.ImageField(blank=True, help_text='建议尺寸 32x32 或 48x48 像素的 PNG 图片,留空则使用默认蓝色圆点', null=True, upload_to='customers/markers/', verbose_name='自定义标记图标'), + ), + ] diff --git a/apps/customers/models.py b/apps/customers/models.py index 3ed771b..7502d92 100644 --- a/apps/customers/models.py +++ b/apps/customers/models.py @@ -11,6 +11,8 @@ class CustomerLocation(models.Model): description_zh = models.TextField('描述说明(中文)', blank=True, default='') description_en = models.TextField('描述说明(英文)', blank=True, default='') marker_color = models.CharField('标记点颜色', max_length=20, default='#165DFF', help_text='十六进制颜色值') + marker_icon = models.ImageField('自定义标记图标', upload_to='customers/markers/', blank=True, null=True, + help_text='建议尺寸 32x32 或 48x48 像素的 PNG 图片,留空则使用默认蓝色圆点') sort_order = models.IntegerField('排序', default=0) is_active = models.BooleanField('启用', default=True) created_at = models.DateTimeField('创建时间', auto_now_add=True) diff --git a/apps/customers/views.py b/apps/customers/views.py index e16cb71..57757ee 100644 --- a/apps/customers/views.py +++ b/apps/customers/views.py @@ -2,6 +2,7 @@ from django.shortcuts import render from django.http import JsonResponse from .models import CustomerLocation from django.utils.translation import get_language +from django.conf import settings def customer_map(request): @@ -12,19 +13,21 @@ def customer_map(request): def customer_locations_api(request): lang = get_language() suffix = 'en' if lang.startswith('en') else 'zh' - locations = CustomerLocation.objects.filter(is_active=True).values( - 'id', f'name_{suffix}', f'address_{suffix}', f'description_{suffix}', - 'latitude', 'longitude', 'marker_color' - ) + locations = CustomerLocation.objects.filter(is_active=True).order_by('sort_order', '-id') data = [] - for loc in locations: + for index, loc in enumerate(locations, start=1): + icon_url = None + if loc.marker_icon: + icon_url = settings.MEDIA_URL + str(loc.marker_icon) data.append({ - 'id': loc['id'], - 'name': loc[f'name_{suffix}'], - 'address': loc[f'address_{suffix}'], - 'description': loc[f'description_{suffix}'], - 'lat': loc['latitude'], - 'lng': loc['longitude'], - 'color': loc['marker_color'] or '#165DFF', + 'id': loc.id, + 'index': index, + 'name': getattr(loc, f'name_{suffix}'), + 'address': getattr(loc, f'address_{suffix}'), + 'description': getattr(loc, f'description_{suffix}'), + 'lat': loc.latitude, + 'lng': loc.longitude, + 'color': loc.marker_color or '#165DFF', + 'icon': icon_url, }) return JsonResponse({'locations': data}) diff --git a/templates/customers/map.html b/templates/customers/map.html index 7b0c459..fd0ad22 100644 --- a/templates/customers/map.html +++ b/templates/customers/map.html @@ -6,10 +6,118 @@ {% block extra_css %} {% endblock %} @@ -20,7 +128,17 @@
{% trans '我们的客户遍布全国各地' %}
- +