| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- $(document).ready(function() {
- $('.ui.dropdown').dropdown();
- $('#login-form')
- .form({
- fields: {
- account: {
- identifier : 'account',
- rules: [
- {
- type : 'empty',
- prompt : '账户名不能为空'
- },
- {
- type : 'length[5]',
- prompt : '账户名长度不得少于5位'
- }
- ]
- },
- password: {
- identifier : 'password',
- rules: [
- {
- type : 'empty',
- prompt : '密码不能为空'
- },
- {
- type : 'length[8]',
- prompt : '密码长度不得少于8位'
- }
- ]
- },
- captcha: {
- identifier : 'captcha-text',
- rules: [
- {
- type : 'empty',
- prompt : '验证码不能为空'
- },
- {
- type : 'length[6]',
- prompt : '验证码长度不得少于6位'
- }
- ]
- }
- }
- });
- $('#form-search-url').form({
- fields:{
- url: {rules:[{
- type:'empty',
- prompt:'链接不能为空'
- }]}
- }
- });
- $('#logs-search-start-date').calendar({
- type:'date',
- text: {
- months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
- monthsShort: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
- },
- formatter: {
- date: function (date, settings) {
- if (!date) return '';
- var day = date.getDate();
- var month = date.getMonth() + 1;
- var year = date.getFullYear();
- return year + '-' + month + '-' + day;
- }
- }
- });
- $('#logs-search-end-date').calendar({
- type:'date',
- text: {
- months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
- monthsShort: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
- },
- formatter: {
- date: function (date, settings) {
- if (!date) return '';
- var day = date.getDate();
- var month = date.getMonth() + 1;
- var year = date.getFullYear();
- return year + '-' + month + '-' + day;
- }
- }
- });
- $('#sidebar-menu').sidebar('attach events', '#sidebar-menu-toggler');
- $('#btn-new-shorturl-modal').click(function(){
- $('#new-shorturl-modal').modal('show');
- });
-
- $('#btn-gen-short-url').click(function() {
- var destUrl = $('#input_dest_url');
- var memo = $('#input_demo');
- var openType = $('#input_open_type')
- if( $.trim(destUrl.val()).length <= 0) {
- errorToast('目标链接不能为空!');
- destUrl.parent().addClass('error');
- return
- }
-
- var data = {
- "dest_url": $.trim(destUrl.val()),
- "memo": $.trim(memo.val()),
- "open_type": $.trim(openType.val()),
- };
- $.ajax({
- type: "POST",
- url: '/admin/urls/generate',
- data: data,
- dataType: 'json',
- success: function() {
- successToast('新建成功!')
- destUrl.val('');
- memo.val('');
- $('#new-shorturl-modal').modal('hide');
- },
- error: function(e) {
- errorToast($.parseJSON(e.responseText).message)
- }
- });
- });//end of #btn-gen-short-url click
- });
- function successToast(message) {
- $('body').toast({
- class: 'success',
- displayTime: 2500,
- message: message,
- showIcon:'exclamation circle',
- showProgress: 'bottom',
- onHidden: function() {location.reload()}
- });
- }
- function errorToast(message) {
- $('body').toast({
- class: 'error',
- displayTime: 2500,
- message: message,
- showIcon:'exclamation circle',
- showProgress: 'bottom'
- });
- }
- function enable_url(url,state) {
- var data = {
- "dest_url": url,
- "enable": state
- }
- $.ajax({
- type: "POST",
- url: '/admin/urls/state',
- data: data,
- dataType: 'json',
- success: function() {
- successToast('操作成功')
- },
- error: function(e) {
- errorToast($.parseJSON(e.responseText).message)
- }
- });
- }
- function delete_url(url) {
- $('body').modal('confirm','温馨提示','确认删除该短链接吗?<br/>本操作将会同步删除该短链接的所有访问日志。', function(choice){
- if (choice) {
- $.ajax({
- type:"POST",
- url: "/admin/urls/delete",
- data : {
- "short_url": url,
- },
- success: function() {
- successToast('操作成功,再见!')
- },
- error: function(e) {
- errorToast($.parseJSON(e.responseText).message)
- }
- });
- }
- });
- }
- function copy_url(url){
- navigator.clipboard.writeText(url);
- $('body').toast({
- class: 'success',
- displayTime: 2500,
- message: '复制成功',
- showIcon:'exclamation circle',
- showProgress: 'bottom'
- });
- }
- function reload_captcha() {
- $.ajax({
- type: "POST",
- url: '/captcha',
- dataType: 'json',
- success: function(r) {
- $('#captcha-image').html('<img src="/captcha/'+r.result+'.png" />');
- $('<input>').attr({type: 'hidden', value:r.result ,name: 'captcha-id'}).appendTo('#login-form');
- },
- error: function(e) {
- errorToast($.parseJSON(e.responseText).message)
- }
- });
- }
- function sign_out_config() {
- $('body').modal('confirm','温馨提示','确认退出 ohUrlShortener 管理后端吗?', function(choice){
- if (choice) {
- $.ajax({
- type:"POST",
- url: "/admin/logout",
- success: function() {
- successToast('操作成功,再见!')
- },
- error: function(e) {
- errorToast($.parseJSON(e.responseText).message)
- }
- });
- }
- });
- }
- function export_accesslog() {
- $('body').modal('confirm','温馨提示','确认导出访问日志?', function(choice){
- if (choice) {
- $("#form-export-logs").submit();
- }
- });
- }
|