[54176ee] | 1 | <script setup lang="ts">
|
---|
| 2 |
|
---|
| 3 | import { ref, getCurrentInstance } from 'vue'
|
---|
| 4 |
|
---|
| 5 | import UploadZone from './UploadZone.vue'
|
---|
| 6 |
|
---|
| 7 | const inst = getCurrentInstance()
|
---|
| 8 |
|
---|
| 9 | const auto_start = ref(false)
|
---|
| 10 | const auto_reset = ref(false)
|
---|
| 11 | const keep_going = ref(false)
|
---|
| 12 | const max_jobs = ref(3)
|
---|
| 13 |
|
---|
[64249d6] | 14 | const can_reset = ref(false)
|
---|
| 15 | const can_start = ref(false)
|
---|
| 16 | const can_pick = ref(false)
|
---|
| 17 | const can_abort = ref(false)
|
---|
| 18 |
|
---|
[54176ee] | 19 | const reset = (): void => {
|
---|
| 20 | (inst as any).refs.uploader.reset()
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | const start = (): void => {
|
---|
| 24 | (inst as any).refs.uploader.start()
|
---|
| 25 | }
|
---|
| 26 |
|
---|
[64249d6] | 27 | const pick = (): void => {
|
---|
| 28 | (inst as any).refs.uploader.pick()
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | const abort = (): void => {
|
---|
| 32 | (inst as any).refs.uploader.abort()
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[d45005e] | 35 | const log = (code: string, args: any[]) => {
|
---|
| 36 | console.log.apply(null, ['>', code].concat(args))
|
---|
| 37 | }
|
---|
| 38 |
|
---|
[54176ee] | 39 | </script>
|
---|
| 40 |
|
---|
| 41 | <template>
|
---|
[64249d6] | 42 | <div class='over'>
|
---|
| 43 | <button @click='pick' :disabled='!can_pick'>pick</button>
|
---|
| 44 | <span> </span>
|
---|
| 45 | <button @click='start' :disabled='!can_start'>start</button>
|
---|
| 46 | <span> </span>
|
---|
| 47 | <button @click='abort' :disabled='!can_abort'>abort</button>
|
---|
| 48 | <span> </span>
|
---|
| 49 | <button @click='reset' :disabled='!can_reset'>reset</button>
|
---|
| 50 | <p />
|
---|
| 51 | <input type='checkbox' v-model='auto_start' id='auto-start' />
|
---|
| 52 | <label for='auto-start'> auto-start</label><br />
|
---|
| 53 | <input type='checkbox' v-model='auto_reset' id='auto-reset' />
|
---|
| 54 | <label for='auto-reset'> auto-reset</label><br />
|
---|
| 55 | <input type='checkbox' v-model='keep_going' id='keep-going' />
|
---|
| 56 | <label for='keep-going'> keep-going</label><br />
|
---|
| 57 | <p />
|
---|
| 58 |
|
---|
| 59 | <component class='uploader' :is='UploadZone' target='https://vite.js29a.usermd.net/upload.php'
|
---|
| 60 | :max-jobs='max_jobs' :auto-start='auto_start' :auto-reset='auto_reset'
|
---|
| 61 | :keep-going='keep_going' ref='uploader'
|
---|
| 62 | @update:canPick='(flag: boolean) => can_pick = flag'
|
---|
| 63 | @update:canStart='(flag: boolean) => can_start = flag'
|
---|
| 64 | @update:canAbort='(flag: boolean) => can_abort = flag'
|
---|
[d45005e] | 65 | @update:canReset='(flag: boolean) => can_reset = flag'
|
---|
| 66 | @debug='(code: string, args: any[]) => log(code, args)'>
|
---|
[64249d6] | 67 | <template #idle='{ pick }'>
|
---|
| 68 | <div class='idle'>
|
---|
| 69 | idle
|
---|
| 70 | <br />
|
---|
| 71 | <button @click='pick()'>pick</button>
|
---|
| 72 | </div>
|
---|
| 73 | </template>
|
---|
| 74 |
|
---|
| 75 | <template #hover>
|
---|
| 76 | <div class='hover'>
|
---|
| 77 | hover
|
---|
| 78 | </div>
|
---|
| 79 | </template>
|
---|
| 80 |
|
---|
| 81 | <template #wait='{ start, queue }'>
|
---|
| 82 | <div class='wait'>
|
---|
| 83 | wait
|
---|
| 84 | <br />
|
---|
| 85 | <button @click='pick()'>pick</button>
|
---|
| 86 | <br />
|
---|
| 87 | <button @click='start()'>start</button>
|
---|
| 88 | <br/>
|
---|
| 89 | <div v-for='file in queue'>{{ file.name }}</div>
|
---|
| 90 | </div>
|
---|
| 91 | </template>
|
---|
| 92 |
|
---|
| 93 | <template #uploading='{ progress, current, queue, abort, errors }'>
|
---|
| 94 | <div class='uploading'>
|
---|
| 95 | uploading
|
---|
| 96 | <br />
|
---|
| 97 | <button @click='abort()'>abort</button>
|
---|
| 98 | <br />
|
---|
| 99 | {{ progress.length }} / {{ current.length }} / {{ queue.length }}
|
---|
| 100 | <b>errors:</b> <span v-for='error in errors'>{{ error.file.name }}</span>
|
---|
| 101 | <b>progress:</b> <div v-for='item in progress'>{{ item }}</div>
|
---|
| 102 | <b>current:</b>
|
---|
| 103 | <div v-for='item in current'>
|
---|
| 104 | {{ item.file.name }}: {{ item.current }} of {{ item.total }}
|
---|
| 105 | </div>
|
---|
| 106 | <b>remaining:</b>
|
---|
| 107 | <div v-for='file in queue'>{{ file.name }}</div>
|
---|
| 108 | </div>
|
---|
| 109 | </template>
|
---|
| 110 |
|
---|
| 111 | <template #done='{ result, reset }'>
|
---|
| 112 | <div class='done'>
|
---|
| 113 | done
|
---|
| 114 | <br />
|
---|
| 115 | <button @click='reset()'>reset</button>
|
---|
| 116 | <br />
|
---|
| 117 | <div v-for='item in result'>{{ item }}</div>
|
---|
| 118 | </div>
|
---|
| 119 | </template>
|
---|
| 120 |
|
---|
| 121 | <template #error='{ error, reset }'>
|
---|
| 122 | <div class='error'>
|
---|
| 123 | error
|
---|
| 124 | <br />
|
---|
| 125 | <button @click='reset()'>reset</button>
|
---|
| 126 | <div>{{ error }}</div>
|
---|
| 127 | </div>
|
---|
| 128 | </template>
|
---|
| 129 |
|
---|
| 130 | <template #aborted='{ result, reset }'>
|
---|
| 131 | <div class='aborted'>
|
---|
| 132 | aborted
|
---|
| 133 | <br />
|
---|
| 134 | <button @click='reset()'>reset</button>
|
---|
| 135 | <div v-for='item in result'>{{ item }}</div>
|
---|
[54176ee] | 136 | </div>
|
---|
[64249d6] | 137 | </template>
|
---|
| 138 |
|
---|
| 139 | <template #with-errors='{ result, errors }'>
|
---|
| 140 | <div class='with-errors'>
|
---|
| 141 | with errors
|
---|
| 142 | <br />
|
---|
| 143 | <b>errors(s):</b>
|
---|
| 144 | <div v-for='item in errors'>{{ item.file.name }} / {{ item.error }}</div>
|
---|
| 145 | <b>ok:</b>
|
---|
| 146 | <div v-for='item in result'>{{ item }}</div>
|
---|
| 147 | </div>
|
---|
| 148 | </template>
|
---|
| 149 | </component>
|
---|
| 150 | </div>
|
---|
[54176ee] | 151 | </template>
|
---|
| 152 |
|
---|
| 153 | <style scoped>
|
---|
| 154 |
|
---|
[64249d6] | 155 | .over {
|
---|
[54176ee] | 156 | position: absolute;
|
---|
| 157 | border-radius: 20px;
|
---|
| 158 | top: 50%;
|
---|
| 159 | left: 50%;
|
---|
| 160 | transform: translate(-50%, -50%);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[64249d6] | 163 | .uploader {
|
---|
| 164 | border: 3px dashed #fff;
|
---|
| 165 | width: 512px;
|
---|
| 166 | height: 384px;
|
---|
| 167 | display: inline-block;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[54176ee] | 170 | .idle,
|
---|
| 171 | .hover,
|
---|
| 172 | .wait,
|
---|
| 173 | .uploading,
|
---|
| 174 | .done,
|
---|
| 175 | .error,
|
---|
| 176 | .aborted,
|
---|
| 177 | .with-errors {
|
---|
| 178 | width: 100%;
|
---|
| 179 | height: 100%;
|
---|
| 180 | border: 1px solid #0ff;
|
---|
| 181 | padding: 5px;
|
---|
| 182 | overflow: auto;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | .status {
|
---|
| 186 | width: 25%;
|
---|
| 187 | height: auto;
|
---|
| 188 | background-color: #555;
|
---|
| 189 | color: #fff;
|
---|
| 190 | position: absolute;
|
---|
| 191 | right: 0px;
|
---|
| 192 | bottom: 0px;
|
---|
| 193 | padding: 2px 2px 2px 2px;
|
---|
| 194 | text-align: center;
|
---|
| 195 | font-weight: bold;
|
---|
| 196 | border-radius: 10px 0px 0px 0px;
|
---|
| 197 | border: 1px solid #0ff;
|
---|
| 198 | opacity: 0.75;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | .idle {
|
---|
| 202 | background-color: #088;
|
---|
| 203 | color: black;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | .hover {
|
---|
| 207 | background-color: #088;
|
---|
| 208 | color: white;
|
---|
| 209 | cursor: copy;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | .wait {
|
---|
| 213 | background-color: #880;
|
---|
| 214 | color: black;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | .uploading {
|
---|
| 218 | background-color: #050;
|
---|
| 219 | color: white;
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | .done {
|
---|
| 223 | background-color: #00f;
|
---|
| 224 | color: white;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | .error {
|
---|
| 228 | background-color: #800;
|
---|
| 229 | color: white;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | .aborted {
|
---|
| 233 | background-color: #300;
|
---|
| 234 | color: white;
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | .with-errors {
|
---|
| 238 | background-color: #800;
|
---|
| 239 | color: white;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | </style>
|
---|
| 243 |
|
---|