setting_bottom.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. {{define "setting_bottom"}}
  2. <script>
  3. var ACTION="{{.action}}";
  4. var QINIU_DOMAIN="{{.qiniu_domain}}";
  5. </script>
  6. <script>
  7. var app=new Vue({
  8. el: '#app',
  9. delimiters:["<{","}>"],
  10. data: {
  11. iframeUrl:"/setting_statistics",
  12. fullscreenLoading:false,
  13. openIndex:[1],
  14. account: {
  15. username: "",
  16. password: "",
  17. },
  18. mysql: {
  19. server: "",
  20. port: "",
  21. database: "",
  22. username: "",
  23. password: "",
  24. },
  25. rules: {
  26. server: [
  27. { required: true, message: '请输入服务地址', trigger: 'blur' },
  28. ],
  29. port: [
  30. { required: true, message: '请输入端口号', trigger: 'blur' },
  31. ],
  32. database: [
  33. { required: true, message: '请输入数据库名', trigger: 'blur' },
  34. ],
  35. username: [
  36. { required: true, message: '请输入用户名', trigger: 'blur' },
  37. ],
  38. name: [
  39. { required: true, message: '请输入用户名', trigger: 'blur' },
  40. ],
  41. avator: [
  42. { required: true, message: '请选择头像', trigger: 'blur' },
  43. ],
  44. role_id: [
  45. { required: true, message: '请选择角色', trigger: 'blur' },
  46. ],
  47. password: [
  48. { required: true, message: '请输入密码', trigger: 'blur' },
  49. ],
  50. nickname: [
  51. { required: true, message: '请输入昵称', trigger: 'blur' },
  52. ],
  53. method: [
  54. { required: true, message: '请输入允许的方法', trigger: 'blur' },
  55. ],
  56. path: [
  57. { required: true, message: '请输入允许的路径', trigger: 'blur' },
  58. ],
  59. },
  60. kefuList:[],
  61. kefuDialog:false,
  62. kefuForm:{
  63. id:"",
  64. name:"",
  65. password:"",
  66. avator:"",
  67. nickname:"",
  68. role_name:"",
  69. role_id:"",
  70. enabled:0,
  71. },
  72. enabledItems: [
  73. {id:2, text: "禁用"},
  74. {id:1, text: "启用"}
  75. ],
  76. domain: QINIU_DOMAIN,
  77. roleList:[],
  78. configList:[],
  79. roleDialog:false,
  80. noticeList:[],
  81. welcomeDialog:false,
  82. ipblackList:[],
  83. welcomeForm: {
  84. content: "",
  85. },
  86. roleForm:{
  87. id:"",
  88. name:"",
  89. method:"",
  90. path:"",
  91. },
  92. statistics:{},
  93. pageindex: {
  94. title_cn: "",
  95. title_en: "",
  96. keywords_cn: "",
  97. keywords_en: "",
  98. desc_cn: "",
  99. desc_en: "",
  100. css_js: "",
  101. html_cn: "",
  102. html_en: "",
  103. },
  104. },
  105. methods: {
  106. //提交表单
  107. setAccount(formName){
  108. let _this=this;
  109. this.$refs[formName].validate((valid) => {
  110. if (valid) {
  111. $.post("/setting_account",_this.account,function(data){
  112. if(data.code==200){
  113. _this.$message({
  114. message: data.msg,
  115. type: 'success'
  116. });
  117. }else{
  118. _this.$message({
  119. message: data.msg,
  120. type: 'error'
  121. });
  122. }
  123. });
  124. } else {
  125. return false;
  126. }
  127. });
  128. },
  129. //设置mysql
  130. setMysql(formName){
  131. let _this=this;
  132. this.$refs[formName].validate((valid) => {
  133. if (valid) {
  134. $.ajax({
  135. type:"POST",
  136. url:"/mysql",
  137. data:_this.mysql,
  138. headers:{
  139. "token":localStorage.getItem("token")
  140. },
  141. success: function(data) {
  142. if(data.code==200){
  143. _this.$message({
  144. message: data.msg,
  145. type: 'success'
  146. });
  147. }else{
  148. _this.$message({
  149. message: data.msg,
  150. type: 'error'
  151. });
  152. }
  153. }
  154. });
  155. } else {
  156. return false;
  157. }
  158. });
  159. },
  160. //重置表单
  161. resetForm(formName) {
  162. this.loading=false;
  163. this.$refs[formName].resetFields();
  164. },
  165. //跳转
  166. openUrl(url){
  167. //window.location.href=url;
  168. this.iframeUrl=url;
  169. },
  170. //展示提示
  171. showNotice(){
  172. this.fullscreenLoading=false;
  173. this.$message({
  174. message: '配置信息写入同级config目录,目录不存在会自动创建!',
  175. type: 'warning',
  176. duration:'8000',
  177. showClose:true,
  178. });
  179. },
  180. addWelcome(){
  181. this.welcomeForm.content="";
  182. this.welcomeDialog=true;
  183. },
  184. //初始化数据
  185. initInfo(){
  186. let _this=this;
  187. if(ACTION=="setting_mysql"){
  188. this.sendAjax("/mysql","get",{},function(result){
  189. _this.mysql.username=result.Username;
  190. _this.mysql.password=result.Password;
  191. _this.mysql.database=result.Database;
  192. _this.mysql.server=result.Server;
  193. _this.mysql.port=result.Port;
  194. });
  195. }
  196. if(ACTION=="setting_kefu_list"){
  197. this.sendAjax("/kefulist","get",{},function(result){
  198. _this.kefuList=result;
  199. });
  200. this.sendAjax("/roles","get",{},function(result){
  201. _this.roleList=result;
  202. });
  203. }
  204. if(ACTION=="roles_list"){
  205. this.sendAjax("/roles","get",{},function(result){
  206. _this.roleList=result;
  207. });
  208. }
  209. if(ACTION=="setting_statistics"){
  210. this.sendAjax("/statistics","get",{},function(result) {
  211. _this.statistics = result;
  212. });
  213. }
  214. if(ACTION=="setting_welcome"){
  215. this.sendAjax("/notices","get",{},function(result){
  216. _this.noticeList=result;
  217. });
  218. }
  219. if(ACTION=="setting_ipblack"){
  220. this.sendAjax("/ipblacks_all","get",{},function(result){
  221. _this.ipblackList=result.list;
  222. });
  223. }
  224. if(ACTION=="setting_config"){
  225. this.sendAjax("/configs","get",{},function(result){
  226. _this.configList=result;
  227. });
  228. }
  229. if(ACTION=="setting_pageindex"){
  230. this.sendAjax("/about","get",{},function(result){
  231. _this.pageindex=result;
  232. });
  233. }
  234. },
  235. sendAjax(url,method,params,callback){
  236. let _this=this;
  237. $.ajax({
  238. type: method,
  239. url: url,
  240. data:params,
  241. headers: {
  242. "token": localStorage.getItem("token")
  243. },
  244. success: function(data) {
  245. if(data.code!=200){
  246. _this.$message({
  247. message: data.msg,
  248. type: 'error'
  249. });
  250. }else if(data.result!=null){
  251. callback(data.result);
  252. }else{
  253. callback(data);
  254. }
  255. _this.fullscreenLoading=false
  256. }
  257. });
  258. },
  259. //添加客服的dialog
  260. addKefu(){
  261. this.kefuForm={
  262. id:"",
  263. name:"",
  264. password:"",
  265. avator:"",
  266. };
  267. this.kefuDialog=true;
  268. },
  269. //提交客服表单
  270. submitKefuForm(formName){
  271. let _this=this;
  272. this.$refs[formName].validate((valid) => {
  273. if (valid) {
  274. this.sendAjax("/kefuinfo","POST",_this.kefuForm,function(result){
  275. _this.kefuDialog=false;
  276. _this.sendAjax("/kefulist","get",{},function(result){
  277. _this.kefuList=result;
  278. });
  279. });
  280. } else {
  281. return false;
  282. }
  283. });
  284. },
  285. //提交欢迎表单
  286. submitWelcomeForm(formName){
  287. let _this=this;
  288. this.$refs[formName].validate((valid) => {
  289. if (valid) {
  290. this.sendAjax("/notice","POST",_this.welcomeForm,function(result){
  291. _this.welcomeDialog=false;
  292. _this.sendAjax("/notices","get",{},function(result){
  293. _this.noticeList=result;
  294. });
  295. });
  296. } else {
  297. return false;
  298. }
  299. });
  300. },
  301. //编辑客服表单
  302. editKefuForm(formName){
  303. let _this=this;
  304. this.$refs[formName].validate((valid) => {
  305. if (valid) {
  306. _this.sendAjax("/kefulist","PUT",_this.kefuForm,function(result){
  307. _this.kefuList=result;
  308. });
  309. } else {
  310. return false;
  311. }
  312. });
  313. },
  314. //获取客服
  315. getKefu(kefuId){
  316. let _this=this;
  317. this.sendAjax("/kefuinfo_setting","GET",{kefu_id:kefuId},function(result){
  318. _this.kefuDialog=true;
  319. _this.kefuForm=result;
  320. _this.kefuForm.password="";
  321. });
  322. },
  323. //删除客服
  324. deleteKefu(kefuId){
  325. let _this=this;
  326. this.sendAjax("/kefuinfo?id="+kefuId,"DELETE",{id:kefuId},function(result){
  327. _this.kefuDialog=false;
  328. _this.sendAjax("/kefulist","get",{},function(result){
  329. _this.kefuList=result;
  330. });
  331. });
  332. },
  333. //删除欢迎
  334. deleteWelcome(id){
  335. let _this=this;
  336. this.sendAjax("/notice?id="+id,"DELETE",{id:id},function(result){
  337. _this.kefuDialog=false;
  338. _this.sendAjax("/notices","get",{},function(result){
  339. _this.noticeList=result;
  340. });
  341. });
  342. },
  343. //删除ip
  344. deleteIpblack(ip){
  345. let _this=this;
  346. this.sendAjax("/ipblack?ip="+ip,"DELETE",{ip:ip},function(result){
  347. _this.sendAjax("/ipblacks_all","get",{},function(result){
  348. _this.ipblackList=result.list;
  349. });
  350. });
  351. },
  352. //配置角色权限
  353. showAuthDialog(id,name,method,path){
  354. this.roleForm.id=id
  355. this.roleForm.name=name
  356. this.roleForm.method=method
  357. this.roleForm.path=path
  358. this.roleDialog=true;
  359. },
  360. //设置配置项
  361. setConfigItem(key,value){
  362. let _this=this;
  363. this.sendAjax("/config","POST",{key:key,value:value},function(result){
  364. _this.sendAjax("/configs","get",{},function(result){
  365. _this.configList=result;
  366. });
  367. });
  368. },
  369. //设置配置项
  370. setWelcomeItem(id,content){
  371. let _this=this;
  372. this.sendAjax("/notice_save","POST",{id:id,content:content},function(result){
  373. _this.sendAjax("/notices","get",{},function(result){
  374. _this.noticeList=result;
  375. });
  376. });
  377. },
  378. //提交角色表单
  379. submitRoleForm(formName){
  380. let _this=this;
  381. this.$refs[formName].validate((valid) => {
  382. if (valid) {
  383. this.sendAjax("/role","POST",_this.roleForm,function(result){
  384. _this.roleDialog=false;
  385. _this.sendAjax("/roles","get",{},function(result){
  386. _this.roleList=result;
  387. });
  388. _this.$message({
  389. message: result.msg,
  390. type: 'success'
  391. });
  392. });
  393. } else {
  394. return false;
  395. }
  396. });
  397. },
  398. //提交首页表单
  399. setPageIndex(){
  400. let _this=this;
  401. this.sendAjax("/about","POST",this.pageindex,function(result){
  402. _this.$message({
  403. message: "编辑成功",
  404. type: 'success'
  405. });
  406. });
  407. },
  408. //生成部署js
  409. createDeployJs(){
  410. let domain=window.location.host;
  411. this.$alert(' <script type="text/javascript">\n' +
  412. ' var GOFLY_KEFU_ID="'+this.kefuForm.name+'";\n' +
  413. ' <\/script>\n'+
  414. ' <script type="text/javascript" src="http://'+domain+'/webjs"><\/script>', '网页部署');
  415. }
  416. },
  417. created: function () {
  418. // if(ACTION=="setting"){
  419. // this.showNotice();
  420. // }
  421. this.initInfo();
  422. }
  423. })
  424. </script>
  425. </html>
  426. {{end}}