Переглянути джерело

新增 前端匯出報到名單功能

maa3520 2 роки тому
батько
коміт
8641dd01e6

+ 1 - 0
.gitignore

@@ -5,6 +5,7 @@
 /public/css
 /public/fonts
 /public/images
+/public/upload
 /storage/*.key
 /vendor
 .env

+ 4 - 3
app/Http/Controllers/CheckInController.php

@@ -143,19 +143,20 @@ class CheckInController extends Controller
     {
         $users = CheckIn::where('activity_id', '=', $request->activity_id)->get();
         $filename = "check_in_list_" . date('Y_m_d_H_i_s',time()) . ".csv";
-        $handle = fopen($filename, 'w+');
+        $filepath = "./upload/".$filename;
+        $handle = fopen($filepath, 'w+');
         fputcsv($handle, array('user_id', 'is_checked_in', 'updated_at'));
 
         foreach ($users as $user) {
             fputcsv($handle, array($user->user_id, $user->is_checked_in, $user->updated_at));
         }
-
+        
         fclose($handle);
 
         $headers = array(
             'Content-Type' => 'text/csv',
         );
 
-        return response()->download($filename, $filename, $headers);
+        return response()->download($filepath, $filename, $headers);
     }
 }

BIN
public/upload/2022年度歲末聯歡抽獎獎品.xlsx


BIN
public/upload/2022年度歲末聯歡摸彩獎品.xlsx


BIN
public/upload/2023年度來賓名單.xlsx


BIN
public/upload/2023年度春酒摸彩獎品.xlsx


+ 27 - 1
resources/js/src/views/lottery/Activities/ActivityPage.vue

@@ -33,6 +33,14 @@
                     </b-card-body>
                 </b-card>
             </b-col>
+            <b-col v-if="this.userData.role == 'Admin'" md="6" :lg="lg">
+                <b-card no-body border-variant="info" class="text-center">
+                    <b-card-body>
+                        <b-button variant="success"
+                            @click="downloadFile">匯出報到名單</b-button>
+                    </b-card-body>
+                </b-card>
+            </b-col>
         </b-row>
     </div>
 </template>
@@ -64,7 +72,25 @@ export default {
         }
     },
     created() {
-        this.userData.role == 'User' ? this.lg = 4 : this.lg = 3;
+        this.userData.role == 'User' ? this.lg = 4 : this.lg = 4;
+    },
+    methods: {
+        downloadFile() {
+            useJwt.postData('/api/checkin/export', { 'activity_id': this.$route.params.activity_id }).then(response => {
+                let blob = new Blob([response.data], {
+                    type: 'application/csv'
+                })
+                let link = document.createElement('a')
+                link.href = window.URL.createObjectURL(blob)
+                link.download = response.headers["content-disposition"].split('filename=')[1]
+                link.click()
+            }).catch(error => {
+                console.log(error)
+                this.user = { name: "查無此人", user_id: " ", department: " " };
+                this.input = "";
+            });
+
+        }
     }
 }
 </script>

+ 0 - 20
resources/js/src/views/lottery/CheckIn.vue

@@ -102,32 +102,12 @@ export default {
 	},
 	data() {
 		return {
-			boxTwo: '',
 			user: { name: " ", user_id: " ", department: " " },
-			scannerText: "",
 			input: "",
 		}
 	},
 	created() {
 
-
-		Pusher.logToConsole = true;
-
-		var pusher = new Pusher('9fb7f6f0141efc7e1293', {
-			cluster: 'ap3'
-		});
-
-		var channel = pusher.subscribe('my-channel');
-		channel.bind('my-event', data => {
-			useJwt.postData('/api/user/show', { 'id': data.message }).then(response => {
-				this.user = response.data.user;
-			}).catch(error => {
-				console.log(error)
-				this.user = {};
-			});
-		});
-
-
 	},
 	computed: {