feat(admin): 新增师傅大厅筛选功能及表格布局组件
- 新增服务品类和服务类型筛选选项 - 新增订单距离筛选功能 - 新增admin-table-layout组件实现表格操作列固定 - 重构后台表格列布局,优化显示效果 - 新增位置相关工具函数及测试用例 - 升级版本号至1.0.89
这个提交包含在:
14
tests/admin_table_layout.js
普通文件
14
tests/admin_table_layout.js
普通文件
@@ -0,0 +1,14 @@
|
||||
const assert = require('assert');
|
||||
const configure = require('../server/public/assets/js/backend/admin-table-layout');
|
||||
let options = {fixedColumns: true, columns: [[{field: 'name', operate: 'LIKE'}, {field: 'operate', class: 'actions', buttons: [1]}]]};
|
||||
configure(options);
|
||||
assert.strictEqual(options.fixedColumns, false);
|
||||
assert.strictEqual(options.columns[0][1].class, 'actions yjyf-table-operate');
|
||||
assert.strictEqual(options.columns[0][0].operate, 'LIKE');
|
||||
assert.deepStrictEqual(options.columns[0][1].buttons, [1]);
|
||||
let plain = {fixedColumns: true, columns: [[{field: 'name'}]]};
|
||||
configure(plain);
|
||||
assert.strictEqual(plain.fixedColumns, true);
|
||||
configure(options);
|
||||
assert.strictEqual(options.columns[0][1].class, 'actions yjyf-table-operate');
|
||||
console.log('admin table layout behavior passed');
|
||||
110
tests/master_hall_filters.js
普通文件
110
tests/master_hall_filters.js
普通文件
@@ -0,0 +1,110 @@
|
||||
const http = require('http');
|
||||
const assert = require('assert').strict;
|
||||
const { execFileSync } = require('child_process');
|
||||
const base = process.env.API_BASE || 'http://yjyf:9560/api';
|
||||
function request(path, method = 'GET', data = '', token = '') {
|
||||
return new Promise((resolve, reject) => {
|
||||
const url = new URL(base + path);
|
||||
const headers = token ? { token } : {};
|
||||
if (data) headers['content-type'] = 'application/x-www-form-urlencoded';
|
||||
const req = http.request(url, { method, headers }, res => {
|
||||
let text = ''; res.on('data', c => text += c); res.on('end', () => {
|
||||
try { resolve(JSON.parse(text)); } catch (e) { reject(new Error(text)); }
|
||||
});
|
||||
});
|
||||
req.on('error', reject); if (data) req.write(data); req.end();
|
||||
});
|
||||
}
|
||||
(async () => {
|
||||
if (!process.env.HALL_TEST_MOBILE || !process.env.HALL_TEST_PASSWORD) throw new Error('请通过环境变量提供 HALL_TEST_MOBILE 和 HALL_TEST_PASSWORD');
|
||||
const login = await request('/auth/login', 'POST', new URLSearchParams({ mobile: process.env.HALL_TEST_MOBILE, password: process.env.HALL_TEST_PASSWORD }).toString());
|
||||
assert.equal(login.code, 1, login.msg);
|
||||
const token = login.data.token;
|
||||
const call = async (params) => {
|
||||
const r = await request('/master/hall?' + new URLSearchParams(params), 'GET', '', token);
|
||||
assert.equal(r.code, 1, r.msg); return r.data;
|
||||
};
|
||||
const initial = await call({ limit: 2, sort: 'new' });
|
||||
assert.ok(Array.isArray(initial.filter_options.categories), '分类选项应来自接口');
|
||||
assert.ok(Array.isArray(initial.filter_options.service_types), '服务类型选项应来自接口');
|
||||
const baseline = await call({ limit: 1, sort: 'new' });
|
||||
assert.equal(initial.total, baseline.total);
|
||||
for (const [key, option, valueKey] of [['cat_id', initial.filter_options.categories[0], 'id'], ['service_type', initial.filter_options.service_types[0], 'code']]) {
|
||||
if (!option) continue;
|
||||
const params = { [key]: option[valueKey], limit: 1, sort: 'new' };
|
||||
const first = await call(params);
|
||||
assert.ok(first.total <= baseline.total, key + ' 不应增加总数');
|
||||
assert.equal(first.has_more, first.total > 1);
|
||||
const second = await call({ ...params, page: 2 });
|
||||
assert.equal(second.total, first.total);
|
||||
if (first.list.length && second.list.length) assert.notEqual(first.list[0].id, second.list[0].id);
|
||||
}
|
||||
const reset = await call({ limit: 1, sort: 'new' });
|
||||
assert.equal(reset.total, baseline.total);
|
||||
for (const filter of [{ distance_km: -1 }, { distance_km: 999 }, { service_type: 'invalid_type' }, { cat_id: 999999 }]) {
|
||||
const rejected = await request('/master/hall?' + new URLSearchParams(filter), 'GET', '', token);
|
||||
assert.notEqual(rejected.code, 1, 'invalid filter must be rejected: ' + JSON.stringify(filter));
|
||||
}
|
||||
const rows = [];
|
||||
for (let page = 1; ; page++) {
|
||||
const result = await call({ limit: 30, page, sort: 'new' });
|
||||
rows.push(...result.list);
|
||||
if (!result.has_more) break;
|
||||
}
|
||||
assert.equal(rows.length, baseline.total);
|
||||
if (rows.length) {
|
||||
const mysql = process.env.HALL_TEST_MYSQL || 'D:\\Softwares\\phpstudy_pro\\Extensions\\MySQL5.7.26\\bin\\mysql.exe';
|
||||
const sql = 'SELECT id,cat_id,lat,lng,HEX(COALESCE(goods_images,\'\')) FROM fa_order WHERE id IN (' + rows.map(r => Number(r.id)).join(',') + ')';
|
||||
const output = execFileSync(mysql, ['-h', '127.0.0.1', '-u', 'yjyf', '-D', 'yjyf', '--batch', '--skip-column-names', '--execute=' + sql], { encoding: 'utf8', env: process.env }).trim();
|
||||
const dbRows = output.split(/\r?\n/).map(line => {
|
||||
const [id, cat, lat, lng, hex] = line.split('\t');
|
||||
let goods = {}; try { goods = JSON.parse(Buffer.from(hex || '', 'hex').toString('utf8')); } catch (_) {}
|
||||
return { id: Number(id), cat: Number(cat), lat: Number(lat), lng: Number(lng), types: (goods.goods_list || []).map(item => item.service_type) };
|
||||
});
|
||||
const info = await request('/master/info', 'GET', '', token);
|
||||
assert.equal(info.code, 1, info.msg);
|
||||
const master = info.data.master;
|
||||
const lat = Number(master.lat), lng = Number(master.lng);
|
||||
const distanceKm = row => {
|
||||
const rad = n => n * Math.PI / 180;
|
||||
const c = Math.sin(rad(lat)) * Math.sin(rad(row.lat)) + Math.cos(rad(lat)) * Math.cos(rad(row.lat)) * Math.cos(rad(row.lng - lng));
|
||||
return 6371 * Math.acos(Math.min(1, Math.max(-1, c)));
|
||||
};
|
||||
const category = initial.filter_options.categories.find(c => dbRows.some(r => r.cat === Number(c.id)));
|
||||
const service = initial.filter_options.service_types.find(t => dbRows.some(r => r.types.includes(t.code)));
|
||||
const cases = [];
|
||||
if (category) cases.push({ cat_id: category.id });
|
||||
if (service) cases.push({ service_type: service.code });
|
||||
if (lat && lng) cases.push({ distance_km: 15 });
|
||||
if (category && service && lat && lng) cases.push({ cat_id: category.id, service_type: service.code, distance_km: 15 });
|
||||
for (const filter of cases) {
|
||||
const expected = dbRows.filter(row => (!filter.cat_id || row.cat === Number(filter.cat_id)) && (!filter.service_type || row.types.includes(filter.service_type)) && (!filter.distance_km || ((row.lat || row.lng) && distanceKm(row) <= Number(filter.distance_km)))).map(r => r.id).sort((a,b) => a-b);
|
||||
for (const sort of ['recommend', 'distance', 'new', 'amount', 'urgent']) {
|
||||
const actual = [];
|
||||
const actualRows = [];
|
||||
let response;
|
||||
for (let page = 1; ; page++) {
|
||||
response = await call({ ...filter, sort, limit: 3, page });
|
||||
actual.push(...response.list.map(r => Number(r.id)));
|
||||
actualRows.push(...response.list);
|
||||
assert.equal(response.total, expected.length, JSON.stringify({ filter, sort }));
|
||||
if (!response.has_more) break;
|
||||
}
|
||||
assert.deepEqual(actual.sort((a,b) => a-b), expected, JSON.stringify({ filter, sort }));
|
||||
for (let i = 1; i < actualRows.length; i++) {
|
||||
if (sort === 'new') assert.ok(Number(actualRows[i - 1].id) > Number(actualRows[i].id));
|
||||
if (sort === 'amount') assert.ok(Number(actualRows[i - 1].pay_amount) >= Number(actualRows[i].pay_amount));
|
||||
if (sort === 'urgent') assert.ok(Number(actualRows[i - 1].urgent) >= Number(actualRows[i].urgent));
|
||||
if (sort === 'distance' && filter.distance_km) assert.ok(Number(actualRows[i - 1].distance_km) <= Number(actualRows[i].distance_km));
|
||||
}
|
||||
assert.equal(response.counts.all, expected.length);
|
||||
for (const type of ['fixed', 'quote', 'custom']) {
|
||||
const typed = await call({ ...filter, sort, type, limit: 1 });
|
||||
assert.equal(typed.total, response.counts[type], type + ' count');
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('verified real orders:', rows.length, 'filter combinations:', cases.length);
|
||||
}
|
||||
console.log('master hall filter API checks passed');
|
||||
})().catch(e => { console.error(e.message); process.exitCode = 1; });
|
||||
35
tests/master_hall_location.mjs
普通文件
35
tests/master_hall_location.mjs
普通文件
@@ -0,0 +1,35 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import fs from 'fs';
|
||||
import vm from 'vm';
|
||||
import { savePickedLocation } from '../yjyf-app/utils/masterHallLocation.mjs';
|
||||
|
||||
let payload;
|
||||
const result = await savePickedLocation(
|
||||
{ latitude: 26.57, longitude: 106.71, name: '测试地点', address: '测试地址' },
|
||||
async (data) => { payload = data; return { location_city: '贵阳市', serve_radius: 20 }; }
|
||||
);
|
||||
assert.deepEqual(payload, { lat: 26.57, lng: 106.71, label: '测试地点' });
|
||||
assert.equal(result.city, '贵阳市');
|
||||
assert.equal(result.serveRadius, 20);
|
||||
await assert.rejects(() => savePickedLocation({ latitude: 0, longitude: 0 }, async () => ({})));
|
||||
await assert.rejects(() => savePickedLocation({ latitude: 26, longitude: 106 }, async () => { throw new Error('保存失败'); }), /保存失败/);
|
||||
|
||||
// Exercise the real cache code with a simulated uni storage boundary.
|
||||
const storage = {};
|
||||
const uni = {
|
||||
getStorageSync: (key) => storage[key],
|
||||
setStorageSync: (key, value) => { storage[key] = value; }
|
||||
};
|
||||
const source = fs.readFileSync(new URL('../yjyf-app/utils/location.js', import.meta.url), 'utf8')
|
||||
.replace(/import \{ tiandituWebKey \} from [^;]+;/, "const tiandituWebKey = ''; ")
|
||||
.replace(/export function /g, 'function ');
|
||||
const context = vm.createContext({ uni, Date, Number, String, Math, Array, Boolean });
|
||||
vm.runInContext(source, context);
|
||||
context.saveManualLocation({ lat: 26.57, lng: 106.71, label: '测试地点', serveRadius: 20, manual: true });
|
||||
storage.yjyf_master_manual_loc_v1.updatedAt = Date.now() - 2 * 86400000;
|
||||
assert.equal(context.getSavedManualLocation().label, '测试地点');
|
||||
assert.equal(context.getSavedManualLocation().manual, true);
|
||||
context.saveManualLocation({ lat: 26.57, lng: 106.71 });
|
||||
storage.yjyf_master_manual_loc_v1.updatedAt = Date.now() - 2 * 86400000;
|
||||
assert.equal(context.getSavedManualLocation(), null);
|
||||
console.log('master hall location tests passed');
|
||||
在新工单中引用
屏蔽一个用户