|
2 | 2 | * @Author: wmhello 871228582@qq.com |
3 | 3 | * @Date: 2022年08月16日 21:01:45 |
4 | 4 | * @LastEditors: wmhello 871228582@qq.com |
5 | | - * @LastEditTime: 2022-08-18 19:49:04 |
| 5 | + * @LastEditTime: 2022-08-19 11:05:19 |
6 | 6 | * @FilePath: \element\src\views\system\snippet\index.vue |
7 | 7 | * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE--> |
8 | 8 | <template> |
@@ -63,7 +63,7 @@ require("codemirror/addon/fold/indent-fold.js"); |
63 | 63 | require("codemirror/addon/fold/markdown-fold.js"); |
64 | 64 | require("codemirror/addon/fold/comment-fold.js"); |
65 | 65 | import { Model } from "@/model/snippet"; |
66 | | -import { listColumns, index } from "@/api/table_config"; |
| 66 | +import { index } from "@/api/table_config"; |
67 | 67 | export default { |
68 | 68 | name: "PreviewIndex", |
69 | 69 | mixins: [CURD], |
@@ -156,27 +156,129 @@ export default { |
156 | 156 | /##back_model##/g, |
157 | 157 | this.tableConfig.back_model |
158 | 158 | ); |
159 | | - // 拼接字符串 |
160 | | - let str = ""; |
| 159 | + |
| 160 | + // 填充字段 |
| 161 | + let format = "##fillable##"; |
| 162 | + let value = null; |
161 | 163 | this.columns.forEach((v) => { |
162 | | - str += `'${v}', `; |
| 164 | + let content = ""; |
| 165 | + content = `'${v}', `; |
| 166 | + value === null ? (value = content) : (value += content); |
163 | 167 | }); |
164 | | - str = "[" + str.slice(0, str.length - 2) + "]"; |
165 | | - this.formData.back_api = this.formData.back_api.replace( |
166 | | - /##fillable##/g, |
167 | | - str || "[]" |
168 | | - ); |
| 168 | + value === null |
| 169 | + ? (value = "[]") |
| 170 | + : (value = "[" + value.slice(0, value.length - 2) + "]"); |
| 171 | + this.formData.back_api = this.formData.back_api.replace(format, value); |
| 172 | + |
| 173 | + // 控制器中的查询 |
| 174 | + format = `$this->model::paginate($pageSize)`; |
| 175 | + value = null; |
| 176 | + this.tableData.forEach((v) => { |
| 177 | + let content = ""; |
| 178 | + if (v.query_type) { |
| 179 | + let title = this.upperToForamt(v.column_name); |
| 180 | + content = `${title}()->`; |
| 181 | + value === null ? (value = content) : (value += content); |
| 182 | + } |
| 183 | + }); |
| 184 | + value === null |
| 185 | + ? (value = format) |
| 186 | + : (value = `$this->model::${value}paginate($pageSize)`); |
| 187 | + this.formData.back_api = this.formData.back_api.replace(format, value); |
169 | 188 | |
170 | 189 | // 处理后端模型 |
171 | 190 | this.formData.back_model = this.formData.back_model.replace( |
172 | 191 | /##back_model##/g, |
173 | 192 | this.tableConfig.back_model |
174 | 193 | ); |
| 194 | + format = "##scopeItem##"; |
| 195 | + value = null; |
| 196 | + this.tableData.forEach((v) => { |
| 197 | + let content = ""; |
| 198 | + if (v.query_type) { |
| 199 | + let title = this.upperToForamt(v.column_name); |
| 200 | + switch (v.query_type) { |
| 201 | + case "=": |
| 202 | + content = ` |
| 203 | + public function scope${title}($query) |
| 204 | + { |
| 205 | + $params = request()->input('${v.column_name}'); |
| 206 | + if ($params) { |
| 207 | + return $query = $query->where('${v.column_name}', $params); |
| 208 | + } else { |
| 209 | + return $query; |
| 210 | + } |
| 211 | + } |
| 212 | + `; |
| 213 | + break; |
| 214 | + case "like": |
| 215 | + content = ` |
| 216 | + public function scope${title}($query) |
| 217 | + { |
| 218 | + $params = request()->input('${v.column_name}'); |
| 219 | + if ($params) { |
| 220 | + return $query = $query->where('${v.column_name}','like', "%".$params."%"); |
| 221 | + } else { |
| 222 | + return $query; |
| 223 | + } |
| 224 | + } |
| 225 | + `; |
| 226 | + break; |
| 227 | + case "<>": |
| 228 | + content = ` |
| 229 | + public function scope${title}($query) |
| 230 | + { |
| 231 | + $params = request()->input('${v.column_name}'); |
| 232 | + if ($params) { |
| 233 | + return $query = $query->where('${v.column_name}', '<>', $params); |
| 234 | + } else { |
| 235 | + return $query; |
| 236 | + } |
| 237 | + } |
| 238 | + `; |
| 239 | + break; |
| 240 | + case "null": |
| 241 | + content = ` |
| 242 | + public function scope${title}($query) |
| 243 | + { |
| 244 | + $params = request()->input('${v.column_name}'); |
| 245 | + if ($params) { |
| 246 | + return $query = $query->whereNull('${v.column_name}'); |
| 247 | + } else { |
| 248 | + return $query; |
| 249 | + } |
| 250 | + } |
| 251 | + `; |
| 252 | + break; |
| 253 | + case "notnull": |
| 254 | + content = ` |
| 255 | + public function scope${title}($query) |
| 256 | + { |
| 257 | + $params = request()->input('${v.column_name}'); |
| 258 | + if ($params) { |
| 259 | + return $query = $query->whereNotNull('${v.column_name}'); |
| 260 | + } else { |
| 261 | + return $query; |
| 262 | + } |
| 263 | + } |
| 264 | + `; |
| 265 | + break; |
| 266 | + } |
| 267 | + value === null ? (value = content) : (value += content); |
| 268 | + } |
| 269 | + }); |
| 270 | + value === null ? (value = "") : (value = content); |
| 271 | + console.log(content); |
| 272 | + // this.formData.back_model = this.formData.back_model.replace( |
| 273 | + // format, |
| 274 | + // value |
| 275 | + // ); |
175 | 276 | // 处理后端资源集合 |
176 | 277 | this.formData.back_resource = this.formData.back_resource.replace( |
177 | 278 | /##back_model##/g, |
178 | 279 | this.tableConfig.back_model |
179 | 280 | ); |
| 281 | + |
180 | 282 | // 处理后端路由 |
181 | 283 | this.formData.back_routes = this.formData.back_routes.replace( |
182 | 284 | /##back_model##/g, |
@@ -211,6 +313,10 @@ export default { |
211 | 313 | ); |
212 | 314 | return data; |
213 | 315 | }, |
| 316 | + upperToForamt(str) { |
| 317 | + str = str.charAt(0).toUpperCase() + str.slice(1); |
| 318 | + return str; |
| 319 | + }, |
214 | 320 | handleClick() {}, |
215 | 321 | async saveHandle() { |
216 | 322 | if ("id" in this.snippet) { |
|
0 commit comments