Просмотр исходного кода

Merge pull request #2414 from visuddhinanda/development

Development
visuddhinanda 5 дней назад
Родитель
Сommit
1feebb1d5d

+ 16 - 8
api-v13/app/Http/Controllers/SentenceController.php

@@ -85,7 +85,7 @@ class SentenceController extends Controller
                     return $this->error('没有关键词');
                 }
                 $table = Sentence::select($indexCol)
-                    ->where('content', 'like', '%'.$key.'%')
+                    ->where('content', 'like', '%' . $key . '%')
                     ->where('editor_uid', $userUid);
 
                 break;
@@ -179,8 +179,16 @@ class SentenceController extends Controller
                 $table = Sentence::where('ver', '>', 1)
                     ->where('book_id', $request->input('book'))
                     ->whereIn('paragraph', explode(',', $request->input('para')))
-                    ->whereIn('channel_uid', explode(',', $request->input('channels')))
                     ->orderBy('book_id')->orderBy('paragraph')->orderBy('word_start');
+                if ($request->has('channels')) {
+                    $table = $table->whereIn('channel_uid', explode(',', $request->input('channels')));
+                }
+                if ($request->has('channel_type')) {
+                    $table = $table->type($request->input('channel_type'));
+                }
+                if ($request->has('lang')) {
+                    $table = $table->language($request->input('lang'));
+                }
                 break;
             case 'my-edit':
                 // 我编辑的
@@ -195,7 +203,7 @@ class SentenceController extends Controller
                 break;
         }
         if (! empty($request->input('key'))) {
-            $table = $table->where('content', 'like', '%'.$request->input('key').'%');
+            $table = $table->where('content', 'like', '%' . $request->input('key') . '%');
         }
 
         $count = $table->count();
@@ -261,7 +269,7 @@ class SentenceController extends Controller
         }
     }
 
-    private function UserCanEdit($userId, $channelId, $book, $access_token = null)
+    private function UserCanEdit(string $userId, string $channelId, int  $book, $access_token = null)
     {
         $channel = Channel::where('uid', $channelId)->first();
         if (! $channel) {
@@ -276,8 +284,8 @@ class SentenceController extends Controller
                     return false;
                 }
                 $key = AccessToken::where('res_id', $channelId)->value('token');
-                $jwt = JWT::decode($access_token, new Key($key.$key, 'HS512'));
-                if ($jwt->book && $jwt->book !== $book) {
+                $jwt = JWT::decode($access_token, new Key($key . $key, 'HS512'));
+                if (isset($jwt->book) && $jwt->book !== 0 &&  $jwt->book !== $book) {
                     return false;
                 }
             }
@@ -308,7 +316,7 @@ class SentenceController extends Controller
             if ($this->UserCanEdit(
                 $user['user_uid'],
                 $request->input('channel'),
-                $request->input('book', 0),
+                (int)$request->input('book', 0),
                 $request->input('access_token', null)
             )) {
                 $destChannel = Channel::where('uid', $request->input('channel'))->first();
@@ -325,7 +333,7 @@ class SentenceController extends Controller
                 if ($this->UserCanEdit(
                     $user['user_uid'],
                     $sent['channel_uid'],
-                    $sent['book_id'],
+                    (int)$sent['book_id'],
                     isset($sent['access_token']) ? $sent['access_token'] : null
                 )) {
                     $destChannel = Channel::where('uid', $sent['channel_uid'])->first();

+ 7 - 0
api-v13/app/Models/Sentence.php

@@ -48,6 +48,13 @@ class Sentence extends Model
         return $this->belongsTo(Channel::class, 'channel_uid', 'uid');
     }
 
+    public function scopeType($query, $type)
+    {
+        return $query->whereHas('channel', function ($q) use ($type) {
+            $q->where('type', $type);
+        });
+    }
+
     public function scopeNissaya($query)
     {
         return $query->whereHas('channel', function ($q) {

+ 17 - 6
dashboard-v6/src/components/token/Token.tsx

@@ -23,6 +23,7 @@ interface IWidget {
 const Token = ({ channelId, articleId, type }: IWidget) => {
   const [text, setText] = useState("");
   const [power, setPower] = useState<TPower>("readonly");
+  const [curr, setCurr] = useState(false);
   const intl = useIntl();
 
   useEffect(() => {
@@ -35,13 +36,13 @@ const Token = ({ channelId, articleId, type }: IWidget) => {
       console.error("channels or book or para is undefined", channelId, id);
       return;
     }
-    const _book = id[0];
+    const _book = parseInt(id[0] ?? "0");
     const _para = id[1];
     const payload: IPayload[] = [];
     payload.push({
       res_id: channelId,
       res_type: "channel",
-      book: parseInt(_book ?? 0),
+      book: curr ? _book : 0,
       para_start: parseInt(_para),
       para_end: parseInt(_para) + 100,
       power: power,
@@ -55,14 +56,24 @@ const Token = ({ channelId, articleId, type }: IWidget) => {
         setText(json.data.rows[0].token);
       }
     });
-  }, [articleId, channelId, power, type]);
+  }, [articleId, channelId, curr, power, type]);
   return (
     <div>
       <div style={{ textAlign: "center", padding: 20 }}>
+        <div>
+          <Segmented
+            key="power"
+            options={["readonly", "edit"]}
+            onChange={(value: SegmentedValue) => {
+              setPower(value as TPower);
+            }}
+          />
+        </div>
         <Segmented
-          options={["readonly", "edit"]}
-          onChange={(value: SegmentedValue) => {
-            setPower(value as TPower);
+          key="curr"
+          options={["current", "all"]}
+          onChange={(value) => {
+            setCurr(value === "current");
           }}
         />
       </div>