| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- const SpssStash = function(setting){
- let init = false;
- const refreshStashListHtml = function(list) {
- const html = [];
- for (const [i, l] of list.entries()) {
- html.push('<tr class="text-center">');
- html.push(`<td>${i+1}</td>`);
- html.push(`<td>${moment(l.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>`);
- html.push(`<td>${l.user_name}</td>`);
- html.push(`<td><button name="load-spss-stash" class="btn btn-sm btn-primary" sid="${l.id}">载入</button></td>`);
- html.push('</tr>');
- }
- $('#spss-stash-list').html(html.join(''));
- };
- const showStash = async function() {
- if (!init) {
- const list = await postDataAsync(setting.url, { type: setting.type, action: 'list' });
- refreshStashListHtml(list);
- init = true;
- }
- $('#spss-stash').modal('show');
- };
- $('#spss-stash-add').click(() => {
- const data = setting.getCurStashData();
- if (!data) return;
- data.type = setting.type;
- data.action = 'add';
- postData(setting.url, data, function(result) {
- refreshStashListHtml(result);
- });
- });
- $('body').on('click', '[name=load-spss-stash]', function() {
- const id = this.getAttribute('sid');
- if (!id) {
- toastr.warning('数据错误,请刷新页面后重试');
- return;
- }
- postData(setting.url, { type: setting.type, action: 'load', id: id }, function(result) {
- setting.loadStashData(result);
- });
- });
- return { showStash }
- };
|