kuaifan пре 5 година
родитељ
комит
63c25a5774

+ 18 - 9
app/Http/Controllers/Api/UsersController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\Api;
 
 use App\Http\Controllers\Controller;
+use App\Model\DBCache;
 use App\Module\Base;
 use App\Module\Users;
 use DB;
@@ -88,6 +89,7 @@ class UsersController extends Controller
         $keys = Request::input('where');
         $whereArr = [];
         $whereFunc = null;
+        $whereRaw = null;
         if ($keys['usernameequal'])     $whereArr[] = ['username', '=', $keys['usernameequal']];
         if ($keys['identity'])          $whereArr[] = ['identity', 'like', '%,' . $keys['identity'] . ',%'];
         if ($keys['noidentity'])        $whereArr[] = ['identity', 'not like', '%,' . $keys['noidentity'] . ',%'];
@@ -96,16 +98,23 @@ class UsersController extends Controller
                 $query->where('username', 'like', '%' . $keys['username'] . '%')->orWhere('nickname', 'like', '%' . $keys['username'] . '%');
             };
         }
-        //
-        $lists = DB::table('users')->select(['id', 'username', 'nickname', 'userimg', 'profession'])->where($whereArr)->where($whereFunc)->orderBy('id')->paginate(Min(Max(Base::nullShow(Request::input('pagesize'), 10), 1), 100));
-        $lists = Base::getPageList($lists);
-        if ($lists['total'] == 0) {
-            return Base::retError('未搜索到任何相关的会员');
+        if (intval($keys['projectid']) > 0) {
+            $whereRaw.= $whereRaw ? ' AND ' : '';
+            $whereRaw.= "`username` IN (SELECT username FROM `" . env('DB_PREFIX') . "project_users` WHERE `type`='成员' AND `projectid`=" . intval($keys['projectid']) .")";
         }
-        foreach ($lists['lists'] AS $key => $item) {
-            $lists['lists'][$key]['userimg'] = Base::fillUrl($item['userimg']);
-            $lists['lists'][$key]['identitys'] = explode(",", trim($item['identity'], ","));
-            $lists['lists'][$key]['setting'] = Base::string2array($item['setting']);
+        //
+        $lists = DBCache::table('users')->select(['id', 'username', 'nickname', 'userimg', 'profession'])
+            ->where($whereArr)
+            ->where($whereFunc)
+            ->whereRaw($whereRaw)
+            ->orderBy('id')
+            ->cacheMinutes(now()->addSeconds(10))
+            ->take(Min(Max(Base::nullShow(Request::input('take'), 10), 1), 100))
+            ->get();
+        foreach ($lists AS $key => $item) {
+            $lists[$key]['userimg'] = Base::fillUrl($item['userimg']);
+            $lists[$key]['identitys'] = explode(",", trim($item['identity'], ","));
+            $lists[$key]['setting'] = Base::string2array($item['setting']);
         }
         return Base::retSuccess('success', $lists);
     }

+ 3 - 0
app/Model/DBCache.php

@@ -150,6 +150,9 @@ class DBCache
 
     public function whereRaw($sql, $bindings = [], $boolean = 'and')
     {
+        if ($sql === null) {
+            return $this;
+        }
         $this->__whereRaw[] = [
             $sql,
             $bindings,

+ 11 - 2
resources/assets/js/main/components/UseridInput.vue

@@ -125,6 +125,9 @@
             noidentity: {
                 default: ''
             },
+            projectid: {
+                default: ''
+            },
             placeholder: {
                 default: ''
             },
@@ -203,6 +206,9 @@
                         if (typeof this.noidentity === "string") {
                             where['noidentity'] = this.noidentity;
                         }
+                        if (this.projectid) {
+                            where['projectid'] = this.projectid;
+                        }
                         $A.aAjax({
                             url: window.location.origin + '/api/users/searchinfo',
                             data: {
@@ -217,7 +223,7 @@
                             },
                             success: (res) => {
                                 if (res.ret === 1 && res.data.total > 0) {
-                                    let tmpData = res.data.lists[0];
+                                    let tmpData = res.data[0];
                                     if (this.multiple) {
                                         this.addMultipleLists(tmpData);
                                     } else {
@@ -325,6 +331,9 @@
                 if (typeof this.noidentity === "string") {
                     where['noidentity'] = this.noidentity;
                 }
+                if (this.projectid) {
+                    where['projectid'] = this.projectid;
+                }
                 $A.aAjax({
                     url: window.location.origin + '/api/users/searchinfo',
                     data: {
@@ -339,7 +348,7 @@
                     },
                     success: (res) => {
                         if (res.ret === 1) {
-                            this.userLists = res.data.lists;
+                            this.userLists = res.data;
                             for (let i = 0; i < this.userLists.length; i++) {
                                 if (this.userLists[i].id == this.userName) {
                                     this.userLists[i]['_highlight'] = true;

+ 1 - 1
resources/assets/js/main/components/project/task/add.vue

@@ -30,7 +30,7 @@
                     <div slot="content">
                         <div style="width:240px">
                             选择负责人
-                            <UseridInput v-model="addUsername" @change="changeUser" placeholder="留空默认: 自己" style="margin:5px 0 3px"></UseridInput>
+                            <UseridInput v-model="addUsername" :projectid="projectid" @change="changeUser" placeholder="留空默认: 自己" style="margin:5px 0 3px"></UseridInput>
                         </div>
                     </div>
                 </Poptip>

+ 2 - 2
resources/assets/js/main/mixins/project.js

@@ -1,7 +1,7 @@
 export default {
     methods: {
-        openProject(projectid) {
-            this.goForward({path: '/project/panel/' + projectid});
+        openProject(projectid, otherParam) {
+            this.goForward({name: 'project-panel', params: {projectid:projectid, other:otherParam||{}}});
         },
 
         outProject(projectid, successCallback) {

+ 16 - 9
resources/assets/js/main/pages/project-panel.vue

@@ -273,23 +273,30 @@
                 loadIng: 0,
                 loadDetailed: false,
 
-                projectid: this.$route.params.id,
+                projectid: 0,
                 projectDetail: {},
                 projectLabel: [],
             }
         },
         mounted() {
-            if ($A.runNum(this.projectid) <= 0) {
-                this.goBack();
-                return;
-            }
-            this.getDetail();
-        },
-        computed: {
 
         },
+        activated() {
+            this.projectid = this.$route.params.projectid;
+            if (typeof this.$route.params.other === "object") {
+                this.$set(this.projectDetail, 'title', $A.getObject(this.$route.params.other, 'title'))
+            }
+        },
         watch: {
-
+            projectid(val) {
+                if ($A.runNum(val) <= 0) {
+                    this.goBack();
+                    return;
+                }
+                this.projectDetail = {};
+                this.projectLabel = [];
+                this.getDetail();
+            }
         },
         methods: {
             getDetail() {

+ 1 - 1
resources/assets/js/main/pages/project.vue

@@ -474,7 +474,7 @@
                     }
 
                     case 'open': {
-                        this.openProject(item.id);
+                        this.openProject(item.id, item);
                         break;
                     }
                     case 'complete':

+ 1 - 1
resources/assets/js/main/routes.js

@@ -14,7 +14,7 @@ export default [
         meta: { slide: false },
         component: resolve => require(['./pages/project.vue'], resolve)
     }, {
-        path: '/project/panel/:id',
+        path: '/project/panel/:projectid',
         name: 'project-panel',
         meta: { slide: false },
         component: resolve => require(['./pages/project-panel.vue'], resolve)