1.不能让网格员一直随时可以修改数据,所以要设计一个开关阀,只有在开关阀开着的期间,才能进行数据修改
1.在后端项目NewCenter的user_operations/models.py中新建表格
class OnOrOff(models.Model): """数据操作开关""" wgz=models.BooleanField(default=False,verbose_name=‘是否开通网格长权限‘) wgy=models.BooleanField(default=False,verbose_name=‘是否开通网格员权限‘) add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = "权限开关表" verbose_name_plural = verbose_name
执行数据更新命令:
python manage.py makemigrations
python manage.py migrate
2.在user_operations/adminx.py中注册:
import xadmin from .models import Notice,OnOrOff class NoticeAdmin(object): list_display = ["user","content","add_time"] list_filter = ["user","content","add_time"] search_fields=["content"] class OnOrOffAdmin(object): list_display = ["wgz","wgy","add_time"] xadmin.site.register(Notice,NoticeAdmin) xadmin.site.register(OnOrOff,OnOrOffAdmin)
3.在xadmin后台,增加一条记录,允许网格长和网格员权限
2.修改潜在bug,因为后端可能要涉及到用户身份权限的修改,所以每一次打开个人中心和操作中心,都应该更新一遍用户的个人信息
1.在后端项目user_operations/views.py中:
class UpUserInfoView(APIView): """更新用户信息""" def get(self, request): token = request.GET.get(‘token‘) if token: user = UserProfile.objects.filter(token=token).first() if user: # 生成token now_time = str(int(time.time())) word = user.mobile + now_time token = hashlib.sha256(word.encode("utf-8")).hexdigest() # print(token) user.token = token user.save() re = UserProfileModelSerializer(user) result = {"status": "200", "data": {‘info‘: re.data, ‘token‘: token}} else: result = {"status": "403", "data": {‘msg‘: ‘请重新登录。‘}} else: result = {"status": "403", "data": {‘msg‘: ‘参数不足‘}} return HttpResponse(json.dumps(result, ensure_ascii=False), content_type="application/json,charset=utf-8")
2.在user_operations/urls.py中增加路由:
from django.urls import path from .views import GetPianQuBannerView,GetNoticeListView,UserLoginView,UpPwdView,GetCaoZuoView,UpUserInfoView urlpatterns = [ path(‘getbanner/‘,GetPianQuBannerView.as_view()),#手机端获取banner图 path(‘getnoticeclist/‘,GetNoticeListView.as_view()),#获取公告列表 path(‘userlogin/‘,UserLoginView.as_view()),#小程序用户登录 path(‘uppwd/‘,UpPwdView.as_view()),#用户修改密码 path(‘getcaozuo/‘,GetCaoZuoView.as_view()),#获取操作数据 path(‘upuserinfo/‘,UpUserInfoView.as_view()),#更新用户个人信息 ]
3.在newapp/page/me/me.vue和center/center.vue中的is_login函数中加入:
//更新个人数据信息开始 let re =await get(‘/user_operations/upuserinfo/‘,{‘token‘:token}) // console.log(111,re) if(re.status==200){ uni.setStorageSync(‘token‘ , re.data.token); uni.setStorageSync(‘info‘ , re.data.info); }else{ uni.removeStorageSync(‘token‘); uni.navigateTo({url:‘/pages/login/login‘}) } //更新个人数据信息结束